DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Web has posted 8 posts at DZone. View Full User Profile

How To Run A Powershell Script From A Scheduler

01.07.2009
| 3089 views |
  • submit to reddit
        // the following script will hide a CMD window if a PowerShell script is run in Windows scheduler

Dim objShell,objFSO,objFile

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

'enter the path for your PowerShell Script
strPath="path_to\script.ps1"

'verify file exists
If objFSO.FileExists(strPath) Then
'return short path name
    set objFile=objFSO.GetFile(strPath)
    strCMD="powershell -nologo -command " & objFile.ShortPath

    '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

    

Comments

Snippets Manager replied on Fri, 2009/07/17 - 6:51pm

Nice scripting solution, you can also use a PS-Script Lauchner (support windows forms code) http://filesystemobject.blogspot.com/2009/04/pscript-der-powershell-script-launcher.html