Here’s another few PowerShell short script to be executed under SQLPS.exe and/or if you already have the SQL Server provider loading on your WindowsPowerShell folder under your user profile. Look for the script “Microsoft.PowerShell_profile.ps1”.
Requirement to run script:
- 1. Must have SQL Server 2008 in order the use the SQL Server provider.
- 2. You could run this script in SQLPS.exe
- 3. Optional-> load your SQL provider in your PowerShell V2 profile. Here’s how: http://blogs.msdn.com/mwories/archive/2008/06/14/SQL2008_5F00_Powershell.aspx (Add this code in your WindowsPowerShell profile)
- 4. Results will be display on screen but you could add code to save result to a file. (" | Out-File …")
This script will list all my SQL Agent jobs on one server or more servers. Remember you can expand this script to do more. This is a teaser code:
More hints: (only if the SQL Provider is loaded)
1. Include the Instance-name or use “Default”.
2. With the right permission use cmdlet: cd SqlServer:\SQL\ Your-SQLServerName to move between SQL servers from one PowerShell console session.
3. This script will run under Windows Authentication.
4. MOST Important… While using both SQL Provider and/or SQLPS.exe you need to close/reopen the PowerShell session to refresh the information.