Run Silent PowerShell Tasks

I was looking online for a way to run a .ps1 file silently from my workstation and found this great post by Jeffery Hicks about how to use WScript to wrapper a powershell command, making use of the ability to run things with a hidden window. For some reason this is the only way I've found to get WPS to run completely silently. Not even the -nologo -noninteractive triggers works as well as this simple script. All you have to do is take the code below and place it into a .vbs file.


Dim objShell,objFSO,objFile

Set objShell=CreateObject("WScript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")

'enter the path for your PowerShell Script

'verify file exists
If objFSO.FileExists(strPath) Then
'return short path name
set objFile=objFSO.GetFile(strPath)
strCMD="powershell -nologo -command " & Chr(34) & "&{" &_
objFile.ShortPath & "}" & Chr(34)
'Uncomment next line for debugging
'WScript.Echo strCMD

'use 0 to hide window
objShell.Run strCMD,0


'Display error message
WScript.Echo "Failed to find " & strPath

End If

Then, edit the file you just created and replace the line that looks like the one below to contain your .ps1 file.

strPath="e:\documents and settings\jhicks\my documents\scripts\posh\Get-DiskSize.ps1"

Now you can open up the windows task scheduler (Start, Run, 'Tasks') and make a task to the VBS file with no triggers required!.
Thanks again Jeffery!