Introduction

This is the 7th instalment of the Automating OpsMgr series. Previously on this series:

I dedicated part 4-6 on creating and managing groups using the OpsMgrExtended module. I was going to continue on this topic and demonstrate how to update group discovery in part 7 (this post), but unfortunately there is a change of plan. While I was preparing for the group discovery update runbook, I noticed I had to firstly cover how to add reference MPs before I can talk about updating group discoveries. I then realised there was a small bug in the New-OMManagementPackReference. Therefore, I have decided to update the OpsMgrExtended module first, before continuing the topics of managing groups.

What’s New?

In this release (version 1.1), I have made the following updates:

  • Bug fix: New-OMTCPPortMonitoring fails when not using the the SMA connection object.
  • Bug fix: New-OMManagementPackReference returned incorrect result when the alias is already used
  • Additional Function / Activity: New-OMComputerGroupExplicitMember
  • Additional Function / Activity: New-OMInstanceGroupExplicitMember
  • Additional Function / Activity: Update-OMGroupDiscovery

In Part 5 and 6, I demonstrated 2 runbooks to add explicit members to computer groups and instance groups. As I mentioned in those posts, I would make those 2 runbooks as native functions within the module, hence the new functions New-OMComputerGroupExplicitMember and OMInstanceGroupExplicitMember. So instead of using the long and complicated runbooks from Part 5 and 6, with this updated version, you can now use very simple runbooks as shown below:

Runbook: Add-ComputerToComputerGroup

Workflow Add-ComputerToComputerGroup
{
  Param(
    [Parameter(Mandatory=$true)][String]$GroupName,
    [Parameter(Mandatory=$true)][String]$ComputerPrincipalName,
    [Parameter(Mandatory=$true)][Boolean]$IncreaseMPVersion
  )

  #Get OpsMgrSDK connection object
  $OpsMgrSDKConn = Get-AutomationConnection -Name "OpsMgrSDK_TYANG"
  $bComputerAdded =New-OMComputerGroupExplicitMember -SDKConnection $OpsMgrSDKConn -GroupName $GroupName -ComputerPrincipalName $ComputerPrincipalName -IncreaseMPVersion $IncreaseMPVersion
  If ($bComputerAdded -eq $true)
  {
    Write-Output "Done."
  } else {
    throw "Unable to add '$ComputerPrincipalName' to group '$GroupName'."
    exit
  }
}

Runbook: Add-ObjectToInstanceGroup

Workflow Add-ObjectToInstanceGroup
{
  Param(
    [Parameter(Mandatory=$true)][String]$GroupName,
    [Parameter(Mandatory=$true)][String]$MonitoringObjectID,
    [Parameter(Mandatory=$true)][Boolean]$IncreaseMPVersion
  )

  #Get OpsMgrSDK connection object
  $OpsMgrSDKConn = Get-AutomationConnection -Name "OpsMgrSDK_TYANG"
  $bInstanceAdded = New-OMInstanceGroupExplicitMember -SDKConnection $OpsMgrSDKConn -MonitoringObjectID $MonitoringObjectID -GroupName $GroupName -IncreaseMPVersion $IncreaseMPVersion
  If ($bInstanceAdded -eq $true)
  {
    Write-Output "Done."
  } else {
    throw "Unable to add monitoring object '$MonitoringObjectID' to group '$GroupName'."
    exit
  }
}

How to Download Updated version?

I have updated the original link, so you can download this updated version at TY Consulting’s web site: http://www.tyconsulting.com.au/portfolio/opsmgrextended-powershell-and-sma-module/

Conclusion

With the updated module in place, I will continue my discussion on managing groups. In the next part of this series, I will demonstrate how to add a management pack reference to an unsealed management pack.

Leave a comment