Suppressing Unwanted Console Window Flash ( Net User )

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
npilzner
Posts: 5
Last visit: Tue Sep 11, 2018 10:32 am

Suppressing Unwanted Console Window Flash ( Net User )

Post by npilzner »

Hello,

I have been working with a script (.PS1) that I would like to turn into an Executable. When I debug my script, or run my script through Powershell Studio/Powershell ISE, the script works as intended. When I package the script into an exe, I get an unexpected console window flash when the net user cmdlet is hit.

I was able to test this and verify it was the net user cmdlet by creating a new .ps1 script containing:

Code: Select all

net user $env:USERNAME /domain | Out-Null
- Which should not yield any output or display anything on the screen.

I tried packaging the above code as SAPIEN Powershell V5 Host (Windows Forms), and SAPIEN Powershell V5 (Windows) but both still yielded the quick flash of the console window.

I have tried changing around the net user cmdlet to

Code: Select all

& powershell.exe -NonInteractive -WindowStyle Hidden -command "net user $env:USERNAME /domain"
Which still warrants the unwanted flash of a console window when packaged.

I would prefer not to have to create a .vbs file to call the script with the -NonInteractive or -WindowStyle flags to accomplish this as a packaged executable will be much more efficient for what I am intending to accomplish.

Is there something that I am missing, or anything left that I should try?

Thanks in advance,
Nick
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Suppressing Unwanted Console Window Flash ( Net User )

Post by jvierra »

Use New-PsDrive as it does not require shelling or external program.
User avatar
npilzner
Posts: 5
Last visit: Tue Sep 11, 2018 10:32 am

Re: Suppressing Unwanted Console Window Flash ( Net User )

Post by npilzner »

I am not familiar with how New-PSDrive would help me retrieve the same User Information that Net User, could you provide an example? When I look at Technet or other similar articles I am not seeing any examples that would fit.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Suppressing Unwanted Console Window Flash ( Net User )

Post by jvierra »

Sorry. I misread your post.

What user information are you trying to receive.

See the following code:
Attachments
Get-ADSystemInfo.ps1
(673 Bytes) Downloaded 119 times
User avatar
npilzner
Posts: 5
Last visit: Tue Sep 11, 2018 10:32 am

Re: Suppressing Unwanted Console Window Flash ( Net User )

Post by npilzner »

I need to be able to retrieve the date their password was last set, or the date it expires.

I know I can achieve this by using Get-ADUser, but the executable would be ran from PCs that do not have rights to AD, let alone have Remote Server Administration Tools installed to import the module. I did not want to hard code a value in their registry as this can easily be tampered with (Especially in HKCU). Net User provides the /domain parameter which allows any of these domain computers to query the domain controller from a non-elevated state.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Suppressing Unwanted Console Window Flash ( Net User )

Post by jvierra »

The function posted does that. It retrieves the whole user AD object. Just select the password last set property.
User avatar
npilzner
Posts: 5
Last visit: Tue Sep 11, 2018 10:32 am

Re: Suppressing Unwanted Console Window Flash ( Net User )

Post by npilzner »

I appreciate the quick replies! I was able to play with that more and you were spot on, seems to be exactly what I was looking for.

Thank you!
This topic is 6 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked