Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How To Run A Powershell Script From A Scheduler

DZone's Guide to

How To Run A Powershell Script From A Scheduler

·
Free Resource
// 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

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}