Operations Manager 2012 R2 Custom PowerShell Module

This Module was updated.

Get-JLabSCOMInfrastructureVersion CmdLet now also recognizes UR9

This post will talk about my new PowerShel SCOM Module.

CmdLets in this Module:
Get-JLabSCOMAgentManagementGroup => Gets to which management Groups Particular Microsoft Monitoring Agent (MMA) is connecting.
Add-JLabSCOMAgentToManagementGroup => Adds MMA to particular management group.
Remove-JLabSCOMAgentFromManagementGroup => Removes MMA from particular management group

Get-JLabSCOMAgentManaged => Gets Agents Which are managed by Particular Management Group
Remove-JLabSCOMAgentManaged => Removes Agent from particular Management Group (for Server deprovisioning)

Get-JLabSCOMInfrastructureVersion => Gets on which UR version is currently our OpsMgr Infrastructure (Can be used to check if upgrade was successful)
Get-JLabSCOMAgentUrVersion => Displays On which UR versions are Agents in our SCOM infrastructure.

Module Can be downloaded from TechNet Gallery.

It has been looong time since my last post. I was quite busy lately but I finally took some time to share something with community. ūüôā

If you were following My posts you already know that I already published PowerShell Module for OpsMgr. I decided to completely rewrite module. I also decided that I will no longer post Check If SCOM was upgraded to UR#. I created a CmdLet which will check on which version particular server in SCOM infrastructure is..

Lets check each individual CmdLet in this module…

First of all run PowerShel or ISE in Elevated mode and then we need to import module => Import-Module .\JLabOperationsManager.psm1
We can always Get-Help to get details regarding what particular CmdLet Does. For example: Get-Help Get-JLabSCOMAgentManagementGroup -Examples returns samples of CmdLet usage.

Get-JLabSCOMAgentManagementGroup

This CmdLet returns to which Management Groups Agent is connected. As we know MMA Agent can be multihomed => That is can report to multiple management groups. We can use this CmdLet to check to which management groups server is reporting.
Sample:

PS C:\> Get-JLabSCOMAgentManagementGroup

managementGroupName                  : MgDummy01
ManagementServer                     : srv01
managementServerPort                 : 5723
IsManagementGroupFromActiveDirectory : False
ActionAccount                        : Local System

PS C:\>

Add-JLabSCOMAgentToManagementGroup

This CmdLet Adds Agent to particular management group. I personaly use this CmdLet to add Agents to Develpoment or Production Management group (sometime both).
Sample:

Adding Management group to local Computer:

PS C:\> Add-JLabSCOMAgentToManagementGroup -ManagementGroupName "Mgmt02" -ManagementServerName "MS01.contoso.com"
[Add-JLabSCOMAgentToManagementGroup]: Adding Agent: Server01 to Management group: Mgmt02

PS C:\>

Then we can Check if Agent was added to Mgmt02:

PS C:\> Get-JLabSCOMAgentManagementGroup

managementGroupName                  : MgDummy01
ManagementServer                     : srv01
managementServerPort                 : 5723
IsManagementGroupFromActiveDirectory : False
ActionAccount                        : Local System

managementGroupName                  : Mgmt02
ManagementServer                     : MS01.contoso.com
managementServerPort                 : 5723
IsManagementGroupFromActiveDirectory : False
ActionAccount                        : Local System

PS C:\>

And we have “Multihomed Agent” Connected to: MgDummy01 and Mgmt02 management Groups

Adding Management group to remote Computers:

Add-JLabSCOMAgentToManagementGroup "Server01","Server02","Server03" -ManagementGroupName "Mgmt01" -ManagementServerName "MS01.contoso.com"

Remove-JLabSCOMAgentFromManagementGroup
This CmdLet Removes Agent from Management groups. Lets suppose we did a mistake and we do not want to have agent in Mgmt02 Management group. We can run:

PS C:\> Remove-JLabSCOMAgentFromManagementGroup -ManagementGroupName "Mgmt01"

[Remove-JLabSCOMAgentFromManagementGroup]: Removing Management Group: Mgmt02 from Computer: Server01
PS C:\>

Again we could check if Agent was removed from management group with Get-JLabSCOMAgentManagementGroup

Get-JLabSCOMAgentManaged
Gets Agents Which are managed by Particular SCOM Management Group. I am using this CmdLet to check if server exists in SCOM as Agent Managed and also to check if server was removed from agent managed on particular Management Group.

PS C:\> Get-JLabSCOMAgentManaged

HealthState DisplayName                              Version       ActionAccountIdentity          ProxyingEnabled
----------- -----------                              -------       ---------------------          ---------------
Success     Server01.contoso.com                7.1.10184.0   SYSTEM                         False
Success     Server02.contoso.com                  7.1.10184.0   SYSTEM                         True
Success     Server03.contoso.com               7.1.10184.0   SYSTEM                         False
Success     Server04.contoso.com                7.1.10184.0   SYSTEM                         True
Success     Server05.contoso.com                   7.1.10184.0   SYSTEM                         False

PS C:\>

Remove-JLabSCOMAgentManaged
I use this CmdLet to deprovision Server(s). We use this script along with removal from SCCM, AD, DNS,… So server will not get back into SCOM it must be offline for good or MMA Service should be disabled.

PS C:\> Remove-JLabSCOMAgentManaged -AgentName 'server01.contoso.com' -ManagementServerName 'OpsMgrSrv01'

We can also provide multiple Agents as an array, from file…

Get-JLabSCOMInfrastructureVersion
This CmdLet is replacement for scripts I wrote in the past to Check if SCOM Infrastructure was upgraded to UR#. We ca use this CmdLet to check if we successfully upgraded our SCOM infrastructure to new UR. We could also use it to check it if All Our OpsMgr 2012 R2 infrastructure is on the same UR version..

PS C:\> Get-JLabSCOMInfrastructureVersion | ft servername,role,urversion -AutoSize

ServerName     Role               UrVersion
----------     ----               ---------
MSsrv01       Management Server  UR8
MSsrv02        Management Server  UR8
MSsrv03        Management Server  UR8
WebSrv01      Web Console Server UR8
GWsrv01        Gateway Server     UR8

PS C:\>

If you have Gateway Server(s) you Will be prompted to enter credentials:

GwCreds

For Gateway server credentials use UPN Name otherwise it might fail. For details why to Use UPN see here.

Get-JLabSCOMAgentUrVersion
When we update OpsMgr Infrastructure we must also upgrade All Agents. To check on Which version are agents we can use this CmdLet.

PS C:\> Get-JLabSCOMAgentUrVersion

UpdateRollup                                                         AgentsCount Agents
------------                                                         ----------- ------
Unknown                                                                        3 {Microsoft.EnterpriseManagement.Admi...
UR4                                                                            8 {Microsoft.EnterpriseManagement.Admi...
UR6                                                                           56 {Microsoft.EnterpriseManagement.Admi...
UR7                                                                            2 {Microsoft.EnterpriseManagement.Admi...
UR8                                                                            1 {Microsoft.EnterpriseManagement.Admi...

PS C:\>

To get this data just a bit more readable:

PS C:\> Get-JLabSCOMAgentUrVersion | select UpdateRollup,AgentsCount | ft -AutoSize

UpdateRollup AgentsCount
------------ -----------
Unknown                3
UR4                    8
UR6                   56
UR7                    2
UR8                    1

PS C:\>

Please note that Under Agents I stored All SCOM Agents of particular UR. Stored Object are type AgentManagedComputer which is returned by Microsoft official Get-SCOMAgent CmdLet. To get List of agents which have UR4 installed we could Run:

PS C:\> (Get-JLabSCOMAgentUrVersion | ? {$_.UpdateRollup -match 'UR4'} | select Agents).agents | select DisplayName

DisplayName
-----------
Server01.contoso.com
Server02.contoso.com
Server03.contoso.com
Server04.contoso.com
Server05.contoso.com
Server06.contoso.com

PS C:\>

Link to module.

Hope that is useful to you. Stay tuned additional CmdLets will come in near future.
C U Soon
Jure

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Operations Manager 2012 R2 Custom PowerShell Module

  1. Pingback: System Center AralńĪk 2015 B√ľlten | Serta√ß Topal

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