O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required