I'm looking for a way to execute a PowerShell script (.ps1) without the terminal window appearing at all. I've tried using the -WindowStyle Hidden option, but the terminal still shows up for a brief moment. Minimizing to the tray isn't the solution I want either. I've seen suggestions for external tools, but I'm concerned about potential security risks. The only reliable method I found involves using VBScript, which can disable the console window, but since VBScript is deprecated by Microsoft, I would prefer a different approach. Are there any other options I could consider?
4 Answers
How are you currently launching the script? Are you using a shortcut on your desktop or in the start menu? It seems like you're using VBScript to run PowerShell. That method does manage to hide the terminal completely.
If wscript.exe isn't blocked, using JScript could also work. Just keep in mind potential restrictions depending on your environment.
It might not be exactly what you want, but converting your script to an executable can completely suppress the terminal window. You could use a module like ps2exe. Here’s a command to do it:
`Install-Module -Name ps2exe -Scope CurrentUser`
Then run:
`Invoke-PS2EXE -InputFile "C:Scriptsscript.ps1" -OutputFile "C:Scriptsscript.exe" -IconFile "C:IconsMailIcon.ico" -NoConsole -Verbose`. Just a tip, if you do this, it will change any `Write-Host` outputs to message boxes instead!
Yes, I wanted to avoid creating a custom EXE. From what I gather, most external tools are essentially C# applications compiled into EXEs, which allow terminal suppression. I'll consider this method, or maybe I should learn enough C# to create my own runner. Thanks!
I've had good results using `conhost.exe --headless`. Just a heads up, some endpoint detection and response (EDR) tools might flag it, though. You can do something like:`conhost.exe --headless powershell.exe -File C:Scriptsmyscript.ps1`. Give it a shot!
Oh wow, it works. Thank you!

Yes, from a shortcut. Right now, the shortcut runs a VBScript that executes PowerShell.