Thursday 12 July 2007

Operation Manager Command Shell on any system

This is a basic guide to get a Operations Manager Command shell on any system without having to install the UI components. You will need to have Powershell and DotNet 3.0 installed on the system.

Copy the Files

You will need to copy some files from your Ops manager install to get the command shell working.

From the Ops Manager installation directory:

Microsoft.EnterpriseManagement.OperationsManager.ClientShell.dll Microsoft.EnterpriseManagement.OperationsManager.ClientShell.dll-help.xml Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Format.ps1xml Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Types.ps1xml

From the SDK Binaries Folder in the O
ps Manager installation directory:

Microsoft.EnterpriseManagement.OperationsManager.dll
Microsoft.EnterpriseManagement.OperationsManager.Common.dll

Copy these files to a folder on the system you want the command shell on. For this example I will copy them to C:\OpsShell.

Register the Powershell Snap-in

For the Powershell snap-in to work we need to register it. As we are not installing the UI this will have to be done manually. Add the below registry settings replacing "C:\\OpsShell" in the following regsitry entries with the correct path to the files.

-----------

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.EnterpriseManagement.OperationsManager.Client] "ApplicationBase"="C:\\OpsShell" "AssemblyName"="Microsoft.EnterpriseManagement.OperationsManager.ClientShell, Version=6.0.4900.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" "ModuleName"="C:\\OpsShell\\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.dll" "PowerShellVersion"="1.0" "Vendor"="Microsoft Corporation" "Version"="6.0.4900.0" "Description"="Microsoft Operations Manager Shell Snapin" "Types"="C:\\OpsShell\\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Types.ps1xml" "Formats"="C:\\OpsShell\\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Format.ps1xml"

-----------


Create the Startup Script

Below is a Powershell script that you can use as a shortcut to start the Command Shell. Copy it to notepad and save it in C:\OpsShell as OpsShell.ps1. Some of the script was borrowed from here

-----------

param ($rootMS)

$rootMS.Length
if ($rootMS -eq $null)
{
$rootMS = Read-Host "Root manangement server"
}

$checksnappin = Get-PSSnapin | where {$_.Name -eq "Microsoft.EnterpriseManagement.OperationsManager.Client"}
if ($checksnappin -eq $null)
{
add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin ;
}
Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin ;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin ;
set-location $rootMS -ErrorVariable errSnapin ;

-----------


Starting the Command Shell

To start the Command Shell open powershell and run C:\OpsShell\OpsShell.ps1.


If you get the error:

File C:\OpsShell\OpsShell.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

Then run this command to change the execution policy:

Set-ExecutionPolicy Unrestricted

This works for me on XP SP2 and Server 2003 SP2

This could be expanded to offer the ability for our server admins to do things such as set Maintenance Mode on or off without having to do it in 3 different locations in the console as is currently needed.



3 comments:

marco.shaw said...

Thanks for posting this! I had wondered if there was a more efficient way to do this.

I don't know if your comments are moderated, but I'd like to talk to you about this post and maybe mention it in a publication. Please contact me at marco DOT shaw _@_ gmail DOT com.

Unknown said...

I noticed that this method doesn't work if you host the files metioned on a network location. You'll get an error that describes that Powershell can't load the files due to security issues.

'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Failed.

This can be fixed by copying the dll files that you mention into the Windows GAC

Anonymous said...

This worked for me, but I had to add the entries to the registry manually. I'm using Vista and Powershell V2