This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
Microsoft Operations Manager 2007(MOM2007), will be build on powershell, so there will be Cmdlets to manage MOM2007 and everything you can do in the GUI you can do in PowerShell.As I'm Implementing a MOM2005 environment as MOM2007 is still in Beta.
So we have to miss the MOM Management Shell (Snap-In) and all those nice Cmdlets as shown at TechEd .
But then again........ Maybe not .
As I had a very good experience with using a .NET DLL from the SMS 2003 SDK (Microsoft.SystemsManagementServer.Automation.dll) See :
PowerShell and SMS 2003I Downloaded the MOM SDK, but no DLL so did look at the .NET examples in the SDK ,
and what seems to be the Case the are allready there, under the MOM programs directory is allready a SDK bin directory, from the examples I did learn that you needed 2 DLL's : Microsoft.Mom.Sdk.dll and mom.context.dll , on My Workstation I could only find Microsoft.Mom.Sdk.dll , but on the MOM ManagementServer the latter was also there, I tried copying it to my client but that did not work, So I installed PowerShell on the Server (As I was lucky that it is our server not the customers I was able to do that) .
And as the DLL's are allready there I needed only this 3 "Magic Lines" and my MOM2005 Management Server was "PowerShell Enabled".
# PowerShell Enable MOM2005
# /\/\o\/\/ 2006
# (works only on MOM managentserver)
# Load Needed DLL's (default Installed)
[System.Reflection.Assembly]::LoadFile("$($env:ProgramFiles)\Microsoft Operations Manager 2005\SDK Bin\Microsoft.Mom.Sdk.dll")
[System.Reflection.Assembly]::LoadFile("$($env:ProgramFiles)C:\Program Files\Microsoft Operations Manager 2005\SDK Bin\mom.context.dll")
# Get a Mom Administration Object
$mom = [Microsoft.EnterpriseManagement.Mom.Administration]::GetAdministrationObject()
# And we are Ready to Go :
# Ask the Object what we can do With it :
$mom | gm
# get groups and puters
$mom.GetComputerGroups() | ft name,ComputerIncludeList
#get agents and states :
$mom.GetAgentManagedComputers() | FT Name,State
# get rulegroups
$mom.GetRuleGroups()
From here on as you also can see in the Acive Directory series I currently running,
its easy to learn from the Object itself using Get-Member (see example above when you run it) and to construct easy Functions to mimic the MOM2007 CDMlets.
e.g. :
PoSH>$mom.GetAgentManagedComputers() | FT NAME,STATE
Name State
---- -----
MS001 Error
MS002 Error
MS012 Warning
MS046 Success
MS047 Success
MS048 Success
# Make it a Function :
Function get-MomAgentManagedComputers {
$mom.GetAgentManagedComputers() | FT NAME,STATE
}
Or as is almost just as easy for most task just just the variable and create (Sub) variables ;-)
# Get RuleGroups
PoSH> $mom.GetRuleGroups()
ID Name Description Enabled
-- ---- ----------- -------
8fff-00... Dell OpenManage Processing rule group for ... True
b050-31... Microsoft Baseline Securit... Microsoft Baseline Securit... True
976a-ca... Microsoft Operations Manager True
afa4-50... Microsoft Operations Manag... Checks that installed MP v... True
a7af-00... Microsoft SQL Server Container for rules to mon... True
87ec-00... Microsoft Windows Internet... Container for rules to mon... True
be95-91... Microsoft Windows Print Se... Microsoft Windows Print Se... True
bb02-42... Microsoft Windows Server 2... Container for rules to mon... True
8b4c-ca... Microsoft Windows Server C... Microsoft Windows Server C... True
8803-00... Microsoft Windows Servers ... Microsoft Windows Servers ... True
# Look at the overloads :
PoSH> $mom.GetRuleGroup
MemberType : Method
OverloadDefinitions : {Microsoft.EnterpriseManagement.Mom.RuleGroup GetRuleGroup(Guid ruleGroupId)}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : Microsoft.EnterpriseManagement.Mom.RuleGroup GetRuleGroup(Guid ruleGroupId)
Name : GetRuleGroup
IsInstance : True
# OK we Need the give the ID :
PoSH> $dell = $mom.GetRuleGroup('00371cb6fed7')
PoSH> $dell
Id Name Description Enabled
-- ---- ----------- -------
8fff-00... Dell OpenManage Processing rule group for ... True
# and a "$dell | get-member" did learn us that we could do this :
PoSH> $dell.GetSubRuleGroups()
Id Name Description Enabled
-- ---- ----------- -------
9b9d-32... State Monitoring and Servi... Rules for Dell state monit... True
98e4-4a... Array Manager Processing rules for Dell ... True
af8e-57... Discovery Discovery of Dell Computers True
b914-68... Management Servers Dell Management Pack Rules... True
9613-87... Server Administrator Processing rules for Serve... True
8573-af... Storage Management Processing rules for Dell ... True
# and so on :
PoSH> $DellStor.GetRules() | ft name,Enabled
Name Enabled
---- -------
Dell_OM_SM Device is missing True
Dell_OM_SM Virtual disk initialization failed True
Dell_OM_SM Predictive Failure reported True
Dell_OM_SM Enclosure power supply has an DC failure True
Dell_OM_SM Enclosure firmware mismatch
PoSH> $DellStor.GetRules()[0]
Id : 05073db6ddca
Name : Dell_OM_SM Device is missing
Enabled : True
EnabledOverride :
AppliedEnabledOverride :
Scripts : {DellOMSALaunch, Dell RAC Console Launch}
RuleThreshold :
# And use the PowerShell Formatting tricks :
# a quick and dirty list of all the computers in the ComputerGroups
$mom.GetComputerGroups() | select name,@{e={$_.ComputerIncludeList |% {"`n$_"}};n='Computers'} | fl
$mom.GetComputerGroups() | select name,@{e={$_.ComputerIncludeList |% {"`n$_"}};n='Computers'} | fl | Out-Printer
This one of the think I love most in MSH and why it is so great,
- find a SDK,
- look for the .NET DLL's
- load them in the Shell,
- get an .NET Object
- ask what it can do ..
- and of you go .... You can start exploring and learning on the Job.
And again... we don't have to wait for the next version (MOM or PoSH),
we can make a headstart.
If there is someone that knows a way to do this on the client (getting a mom.context.dll that works on the client I think is needed) that would be realy great, so if any MOM guru is reading this, and knows how to do this, please leave a comment.
Enjoy,
Greetings /\/\o\/\/
Tags : Monad msh PowerShell MOM