Custom SCOM 2012 PowerShell Module – Version 1.3

A while ago I created PowerShell Module for SCOM 2012. This are the “CMDlet-s” which are currently available:

Get-MySCOMMonitorErrorStatus
Reset-MySCOMMonitorStatus
Update-MySCOMMonitorStatus
Get-MySCOMmonitorParents
Get-MySCOMRuleConfiguration

This Module was updated on 7.10.2014. Current version is 1.3

Changes from previous release:

4 CMDlets were added:
Add-mySCOMAgentToManagementGroup
Get-mySCOMAgentManagementGroup
Remove-mySCOMAgentManagementGroup
Get-MySCOMConnectedUsers

Now lets go step by step and check what each one does.

But first let me explain that some monitors states are differently named under the hood of OpsMgr. For example monitor in Healthy state is in SCOM language “Success”:
MonStates2

Second I will also explain is how to load this module. It is the same as with any other module. Browse with powershell in folder where MySCOMcmdlets.psm1 resides and run:
Import-Module .\MySCOMcmdlets.psm1

OK now lets go into the details of functions..

Get-MySCOMMonitorErrorStatus

This function returns all “Monitor instances” that are in particular state. Default value of monitor is Error.

Here is an example below command returns all “Buffer Cache Hit Ratio” Monitors of all Class instances that are in Error state:

Command:
Get-MySCOMMonitorErrorStatus “Buffer Cache Hit Ratio” -State “Success”

Output:
Server Name: Server02.contoso.com
Monitor Name: Buffer Cache Hit Ratio
Monitor State: Success
————————–
Server Name: Server03.contoso.com
Monitor Name: Buffer Cache Hit Ratio
Monitor State: Success
————————–

Reset-MySCOMMonitorStatus

This function resets health of all Class instances that are in particular State.

Reset-MySCOMMonitorStatus “Buffer Cache Hit Ratio”

Server01.contoso.com
Reseting Health for: Buffer Cache Hit Ratio

Also a bunch of data is returned: TaskId, BatchId,…

————————–

Using wildchard is also possible but be aware if you set scope too high monitors that you do not want them to be reseted could be reseted. I would not advise to use Reset-MySCOMMonitorStatus * 🙂

Reset-MySCOMMonitorStatus “Service Principal Name Config*” -State “warning”
Server02.contoso.com
Reseting Health for: Service Principal Name Configuration Status

Update-MySCOMMonitorStatus

Sometimes we repair something and we would like to recalculate Monitor for all instances. It that case use below fuction.

Update-MySCOMMonitorStatus “Buffer Cache Hit Ratio”
Server01.contoso.com
Recalculating Health for: Buffer Cache Hit Ratio

Also a bunch of data is returned: TaskId, BatchId,…
————————–

Get-MySCOMMonitorParents

This functions returns provided monitor parents, so we can for example easier find monitor through Health explorer so we can get previous states.

Get-MySCOMMonitorParents “Health Service Handle Count Threshold”
Entity Health
└Performance
└System Center Management Health Service Performance
└System Center Management Health Service Memory Utilization
└Health Service Handle Count Threshold

Get-MySCOMRuleConfiguration

Last but not least this function returns rule configuration. If we for example want quickly see what is default value of frequency for a particular rule we can use this function. At first glance output seems cryptic but when we look closer we can see: <Fr
equency>300</Frequency> Which means that this rule is trigered every 300 Seconds.

Get-MySCOMRuleConfiguration “System Processor Queue Length Windows Server 2012″

DisplayName        : System Processor Queue Length Windows Server 2012
Name               : Microsoft.Windows.Server.6.2.OperatingSystem.SystemProcessorQueueLength.Collection
ManagementPackName : Microsoft.Windows.Server.2012.Monitoring
Enabled            : true
XmlTag             : Rule
Description        : Collection rule for the performance counter System\Processor Queue Length.
Configuration for: System Processor Queue Length Windows Server 2012 is:

<ComputerName>$Target/Host/Property[Type=”Windows!Microsoft.Windows.Computer”]/NetworkName$</ComputerName><CounterName>
Processor Queue Length</CounterName><ObjectName>System</ObjectName><InstanceName/><AllInstances>false</AllInstances><Fr
equency>300</Frequency><Tolerance>10</Tolerance><ToleranceType>Absolute</ToleranceType><MaximumSampleSeparation>12</Max
imumSampleSeparation>

———————————–
This function also excepts wildchards:
Get-MySCOMRuleConfiguration “System Processor Queue Lengt*”

Add-mySCOMAgentToManagementGroup

This function Adds SCOM Agent(s) to Management Group. You can provide single or multiple servers. This function excepts wildchards.

Sample: Add-mySCOMAgentToManagementGroup “Server01″,”Server02″,”Server03” -ManagementGroupName “Mgmt01” -ManagementServerName “MS01.contoso.com”
Default port: 5723 is used

Note: Agent has to be connected to one of management groups. If you would like to manipulate Agent Management Group membership directly, you can use Script in this Post

Get-mySCOMAgentManagementGroup

This function displays Management Group(s) of Microsoft Monitoring Agent(s)
Sample: Get-mySCOMAgentManagementGroup “Server*”,”SQLSrv*”

Remove-mySCOMAgentManagementGroup

This function REMOVES Management Group from Microsoft Monitoring Agent(s)
Sample: Remove-mySCOMAgentManagementGroup “Server*”,”SQLSrv*” -ManagementGroupName “MGMT01”

Get-MySCOMConnectedUsers

This function returns Connected users to Management Group
Usage: Get-MySCOMConnectedUsers

 

Module can be downloaded from Here

That is it for now. Stay tuned since module will be extended in the future 😉

Share knowledge and ask questions. There are no stupid questions, just stupid answers. 😉

Oh and one more thing. Names of “cmdlets are not by the book. I always ad “My” in between: for example Get-MySCOMtest so I can select them faster and also to differentiate my Cmdlets from built in ones.

C U Soon
Jure

Advertisements
This entry was posted in Operations Manager, PowerShell and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s