Databases Reference
In-Depth Information
For servers on which you have SQL Server 2008 R2 or later installed, you also have the option to
execute PowerShell as a SQL Server Agent job. This is easily achieved by creating a new step for
a job and selecting PowerShell from the Type drop-down box. You can then enter the PowerShell
script into the Command text box.
Unfortunately using PowerShell jobs in SQL Server 2008 R2 was not very useful because it would
call into PowerShell version 1.0 so many scripts and modules would not work properly. If you want
to execute scripts written for PowerShell 2.0 from SQL Server 2008 R2 you are best off using the
execute PowerShell.exe method described earlier. Fortunately this is resolved in SQL Server 2012
because it will load PowerShell 2.0
The advantage of using the SQL Server job agent is that you may already have jobs running, and this
approach enables you to manage all your jobs in one place. You can also use the logging functional-
ity already built into the SQL Job engine to monitor the execution of the PowerShell script.
SUMMARY
This chapter introduced you to PowerShell's core concepts and provided examples of how
PowerShell can be used in a troubleshooting and performance analysis scenario. The scope of
possibilities for using PowerShell in a SQL Server environment are almost endless; and where the
product team hasn't provided full functionality, the user community has i lled the gap in the
form of the SQLPSX and PSX libraries on CodePlex.
You are now aware of how you can build your own library of useful functionality within a module,
and you have the tools and knowledge to share these with other members of your team or the wider
population.
PowerShell is an area of administration that is still in its early stages, and it is being actively devel-
oped by the SQL Server team and the Windows team, as well as by other product groups. However,
now is the perfect time to begin using this rich shell and scripting environment, and the trusted
toolkit it provides, which enable you to be more efi cient as a DBA and to maintain a calm and
coni dent attitude when facing production issues.
 
Search WWH ::




Custom Search