/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" PowerShell and Active Directory Part 2 "," PowerShel and Active Directory Part 1 "," TechEd RoundUp "," A big hurray for the Scripting Guy ! "," Teched "," PowerShell Tab Completion Part 4 "," The DFO Show - Introducing Windows PowerShell "," PowerShell Tab Completion Part 3 of more ? "," PowerShell Tab Completion Part 2 "," The Microsoft Code "," ")

Thursday, June 29, 2006

 


PowerShell and MOM 2005



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 2003

I 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 :


Comments:
Anonymous Anonymous
Nice post. Unfortunately, the MOM 2005 SDK must run on a MOM management server. it is not remoteable. From what I understand, MOM 2007 will fix this limitation.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/momsdk/HTM/R_MCL/MOM_Microsoft.EnterpriseManagement.Mom.ManagementServer.InsertConsoleScope.asp
 
Blogger /\/\o\/\/
Joe,

Thanks for the reaction,
only the link was wrong, I did find the information here, (MSDN link updating problem)

http://msdn.microsoft.com/library/en-us/momsdk/HTM/P/MOM_P_MCLUsing.asp?

Greetings /\/\o\/\/
 
Blogger Pete Zerger
Based on the output of the '$mom | gm' command, it would appear we're limited to read-only? (I only see Get options, no Set options)
 
Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?