views:

613

answers:

2

How is it possible to run a PowerShell script without displaying a window or any other sign to the user?

In other words, the script should run quietly in the background without any sign to the user.

Extra credit for an answer that does not use third party components :)

+1  A: 

You can use the PowerShell Community Extensions and do this:

start-process PowerShell.exe -arg $pwd\foo.ps1 -WindowStyle Hidden

With VBScript:
http://blog.sapien.com/index.php/2006/12/26/more-fun-with-scheduled-powershell/

[via http://www.wiredbox.net/forum2/Thread72441%5FHow%5Fto%5Frun%5Fpowershell%5Fscript%5Fwithout%5Fconsole%5F.aspx%5D

ax
+6  A: 

You can either run it like this (but this shows a windows for a while):

PowerShell.exe -windowstyle hidden { your script.. }

Or you use a helper file I created to avoid the window called PsRun.exe that does exactly that. You can download source and exe file Run scheduled tasks with WinForm GUI in PowerShell. I use it for scheduled tasks.

Edited: as Marco noted this -windowstyle parameter is available only for V2.

stej
Nice tip. I need it for a scheduled task as well :)
Thomas Bratt
For anyone coming along and trying this, you need PowerShell v2 to get the -WindowStyle parameter.
Marco Shaw