r/PowerShell • u/JackNotOLantern • Feb 20 '26
Run powershell without terminal window
How to run ps1 script without the terminal window showing up at all?
Using -WindowStyle Hidden still shows the terminal for a moment. Minimising to tray is also not the solution i am looking for.
I saw there are external tools but they are a potential security risk.
The only way I found that works is using vbs and disabled the console window inside it. However, vbs has some other issue, and is deprecated by Microsoft currently, so i would rather find another way.
So, are there any other solutions?
Edit:
It seems that running ps1 by using conhost is the solution i needed.
conhost --headless powershell -File script.ps1 ...
41
u/Gakamor Feb 20 '26
I've used "conhost.exe --headless" in the past for that. Be aware that some EDR get grumpy about it.
conhost.exe --headless powershell.exe -File C:\Scripts\myscript.ps16
u/desatur8 Feb 20 '26
Probably not a solution for you, but if you convert to exe, you have the option to surpress the terminal completely, and any write host outputs will be converted to messageboxes.
Install-Module -Name ps2exe -Scope CurrentUser
Invoke-PS2EXE -InputFile "C:\Scripts\script.ps1" -OutputFile "C:\Scripts\script.exe" -IconFile "C:\Icons\MailIcon.ico" -NoConsole -Verbose
Typing from mobile, and not sure how to do codeboxes, sorry
9
u/nkasco Feb 20 '26
This is a longstanding discussion, it used to be that you needed a vbscript wrapper but I think someone found an alternate solution. The discussion is available here: https://github.com/PowerShell/PowerShell/issues/3028
5
u/Certain-Reference291 Feb 20 '26
We are using silentcmd of GitHub.
1
u/drchigero Feb 23 '26
You can do this, but keep in mind this level of hiding it from the user will trigger EDRs as potentially malicious. And if you're doing this in a company the infosec guys will (and should) shut this down.
1
u/_Buldozzer Feb 24 '26
I wrote myself a VBS script, that calls PowerShell silently and can accept parameters.
1
u/BetrayedMilk Feb 20 '26
How are you launching the script?
1
u/iliark Feb 20 '26
Reddit keeps deleting my sample code, but using JScript works if wscript.exe isn't blocked.
1
u/quantgorithm Feb 20 '26
Run it as a different user like the admin profile on the machine.
1
u/jeffrey_f Feb 21 '26 edited Feb 21 '26
Invoke-Command -ComputerName localhost -FilePath "C:\path\to\script.ps1"
Or for multiple lines
Invoke-Command -ComputerName localhost -ScriptBlock {
# your code here
}
I do this on computers at my work so I can do stuff, but not disturb the users
1
u/Losha2777 Feb 21 '26
I have used psadt. (not the whole thing for this)
Just taken the "Invoke-AppDeployToolkit.exe**"** to launch my own scripts
1
u/Harze2k Feb 21 '26
You can create an exe file like this and then just launch the file by running the exe: PowershellSilentLaunch.exe "C:\path\to\ps\file.ps1"
You can change the powershell.exe to pwsh.exe to create an exe file to launch files silently with PS 7+
You can play around with args to make it accept parameters as well.