Have your PowerShell and our Cmdlets too...
Adding the Operations Manager Snapin
As you may already know, the PowerShell is an extensible environment, as such we have tried to create a useful starting point for you by loading the Operations Manager Cmdlets and functions within a PowerShell environment named “Command Shell”. For those of you who need to customize the PowerShell experience the "Command Shell" may not meet your needs. If you want access to Operations Manager Cmdlets from any PowerShell instance you must first load the Operations Manager snapin. Here is an example.
Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client
Before you can start using the Operations Manager Cmdlets you must set the location to the root of the Operations Manager snapin. There are several ways of working with a provider. I recommend you create a drive so you can easily work with multiple Operations Manager connections.
# Set the location to the root of the provider namespace.
cd OperationsManagerMonitoring::
# or
# Create a drive that maps to the root of the provider namespace.
New-PSDrive -Name: Monitoring -PSProvider: OperationsManagerMonitoring -Root: \
cd Monitoring:\
Now that you are working with the correct provider you can create a connection to the Management Group you intend to manage.
# Replace 'localhost' with the name of your server if connecting remotely.
New-ManagementGroupConnection localhost
cd localhost
Creating A Console File
That was fairly easy but what if you want to automate these commands every time you start the PowerShell. That requires adding a startup script and/or a console file. I suggest creating a console file to begin with to make the management of snapins easier.
Start by creating a copy of the PowerShell shortcut.
Create a new console file by launching the new shortcut and running the following commands.
Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client
Export-Console $home\myconsole
Close the PowerShell instance and open the properties of the new shortcut. Add the following as a parameter to powershell.exe in the Target field.
-PSConsoleFile myconsole.psc1
Adding A Startup Script
Now launch the new PowerShell shortcut. You may notice that the Operations Manager startup banner is missing as well as the default connection and all of the Operations Manager functions. The startup banner and functions can also be included in the startup of your custom PowerShell instance by creating a startup script.
Start by creating a file called mystartup.ps1 located in $home from within PowerShell. Add the following lines to the startup script to move to the Operations Manager installation directory.
$pf = (gc Env:\ProgramFiles)
cd "$pf\System Center Operations Manager 2007"
To add ONLY the Operations Manager functions add the following line to your script. If you decide to go this route you should also consider adding commands to connect to the Management Group you itend to manage.
.\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Functions.ps1
To add the Operations Manager functions, the default connection and the startup banner add the following line to your startup script. I suggest using this approach until you are familiar with Operations Manager connection Cmdlets.
.\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Startup.ps1
Now you need to call the startup script from your PowerShell shortcut. Open the shortcut properties and add the following arguments at the end of the Target field.
-NoExit .\mystartup.ps1
That’s it! Now you can fully customize your powershell startup experiance while still having immediate access to Operations Manager functionality.
Comments
Anonymous
January 05, 2007
I have updated this post several times because of your feedback. Please take the time to read the whole post as it will address issuses regarding the loading of Operations Manager functions like Get-OperationsManagerCommand. I also added info on setting the correct provider location which is necessary before running any of the Operations Manager Cmdlets.Anonymous
August 08, 2011
Thank you very much. I was looking for this for a long time.