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.

PSWrapper.vbs

Dim objShell,objFSO,objFile

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

'enter the path for your PowerShell Script
strPath="C:\bri\bkupspace.ps1"

'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

Else

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

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!

1 Response to “Run Silent PowerShell Tasks”


  1. 1 Jake

    Found a way to do this also. Use a scheduled task and have the task run under a local account or an account which is not logged in so it doesn’t display. The process still shows up in task manager though. And this should work with any task, not just batch files and cscripts (I have not tried it with Powershell)
    Jake

Leave a Reply