Scheduling Scripts

From time to time, it may be useful to have a method to schedule PowerShell scripts and have them run automatically (when the SQL Server Agent isn’t available locally, for example). The key to scheduling PowerShell scripts is the ability to call PowerShell and have it run the related scripts. There are a number of ways to accomplish this. One way is to call the powershell.exe with the -Command parameter. You can easily view the help related to this method by simply typing powershell.exe /? from a PowerShell session, as shown here:

PS>powershell.exe /?...PowerShell -Command "& {Get-EventLog -LogName security}"...

Only a small section of the text displayed is shown in this example. The powershell.exe ...

Get Microsoft® SQL Server 2012 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.