Sync SCVMM Hosts to SCOM Groups

Much like in my previous post about syncing SCVMM VMs to SCOM Groups, we can Sync SCVMM Hosts to SCOM Groups.  I will show you how you can create SCOM groups from your SCVMM Host groups. Several reason you might want to do this is maintenance mode of an entire cluster, setting custom monitors or rules for that particular cluster. For instance if its a lab cluster you maybe want to monitor it but not necessarily get critical alerts in the middle of the night from it.

What you’ll need:

– Powershell Read Rights to VMM (Remote rights if using it from a different PC)
– At least Author Rights to SCOM as the script will create SCOM Groups and add VMs to them
– The VMM, OpsMgr and OpsMgrSDK Powershell Modules all installed on the machine running the script
I typically run this script from a Operations Manager Management Server, as VMM has much better support for remote commands. The OpsMgrSDK doesn’t have any support for remote commands. You will need to use invoke-command to use commands remotely
This script uses elements of my SCOM Group creation found here
#import VMM, OpsMgr and OpsMgrSDK Powershell Modules
import-module virtualmachinemanager
import-module operationsmanager

#VMM, SCOM servers and Domain. Change to your environment
$vmmserver = 'vmm01.sandlot.dom'
$scomserver = 'om01.sandlot.dom'
$domain = 'sandlot.dom'
$mp = ""

#get all VMM Hosts selecting their names and clusternames
$hosts = get-vmhost -VMMServer $vmmserver | Select-Object computername,hostcluster,VMHostGroup

#New-OMManagementPack -SDK $scomserver -DisplayName "Custom Cloud Groups" -Name ""

$mp = get-scommanagementpack -Name $mp

foreach($vmhost in $hosts)
$computer = $vmhost.computername
$cluster = $vmhost.hostcluster
$hostgroup = $vmhost.vmhostgroup

#VMM puts "all hosts" in front of each host group
$hostgroup = $hostgroup -replace "All Hosts\\",""

#I used this with 3 different host clusters, your needs may vary.
$verify = get-scomgroup -displayname $hostgroup

if($verify -eq $null)
$create = new-omcomputergroup -sdk $scomserver -MPname $mp.Name -computergroupname "HyperVHost.$hostgroup" -computergroupdisplayname "HyperVHost Group $hostgroup"
start-sleep -Seconds 400
$groupadd = New-OMComputerGroupExplicitMember -SDK $scomserver -GroupName $verify.FullName -ComputerPrincipalName "$computer.$domain" -Verbose -Debug
} Else {$groupadd = New-OMComputerGroupExplicitMember -SDK $scomserver -GroupName $verify.FullName -ComputerPrincipalName "$computer.$domain"}



Hi, I’m Billy York.  I’m a Cloud and Datacenter Engineer, specializing in monitoring and automation. Here you’ll find posts about System Center Operations Manager, Powershell, Hyper-V, Azure Automation, Azure Log Analytics and other Microsoft related technologies.