How can I run a PowerShell script without showing the terminal window?

0
12
Asked By CuriousCoder92 On

I'm looking to execute a PowerShell script (.ps1) without having the terminal window flash on screen at all. I've tried the -WindowStyle Hidden option, but it still briefly shows the terminal. I want to avoid minimizing the window or utilizing external tools that might pose a security risk. The only effective method I found so far is using VBScript to hide the console, but since VBScript is deprecated by Microsoft, I'm keen on finding an alternative approach. Any suggestions?

2 Answers

Answered By ScriptMaster78 On

If it helps, converting the script to an executable (.exe) is another option to completely suppress the terminal. You can do this using the ps2exe module. Here’s how: 1. Install the module with `Install-Module -Name ps2exe -Scope CurrentUser`. 2. Then run `Invoke-PS2EXE -InputFile "C:Scriptsscript.ps1" -OutputFile "C:Scriptsscript.exe" -IconFile "C:IconsMailIcon.ico" -NoConsole -Verbose`. Just a heads up, though, this requires creating a custom .exe, which isn’t what you’re looking for but might be a solid workaround!

CuriousCoder92 -

Yes, I wanted to avoid creating a custom exe. I get that many of these tools are C# applications compiled into exe. I'll give your suggestion a shot, or I might just learn enough C# to create my own runner if nothing else works. Thanks!

Answered By TechWhiz345 On

You can try running your script with `conhost.exe --headless` to suppress the terminal window. Just be cautious, as some Endpoint Detection and Response (EDR) tools might flag this. Here's the command you can use: `conhost.exe --headless powershell.exe -File C:Scriptsmyscript.ps1`. It works well for me!

CuriousCoder92 -

Oh wow, it works. Thank you!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.