Menu Close

How to get all Cluster Virtual Servers and their possible Nodes from SCOM

image

I have had to use this a few times for customers so I thought I might publish it.  Comes in handy when managing alerts from cluster objects and associating them with a physical node, or when extending computer properties.

 

# Get Virtual Servers Array $VirtualServers = Get-SCOMClass -name 'Microsoft.Windows.Cluster.VirtualServer' | Get-SCOMClassInstance | Sort #Get the relationship $rid = Get-SCOMRelationship -DisplayName 'Health Service manages Entity' #Set Array to empty [array]$VirtualClusterItems = @() FOREACH ($VirtualServer in $VirtualServers) { [string]$VirtualServerName = $VirtualServer.DisplayName #Create a PowerShell Object to assign properties $VirtualClusterItem = New-Object PSObject $VirtualClusterItem | Add-Member -type NoteProperty -Name 'VirtualServer' -Value $VirtualServerName #Get the nodes in an array which have a health service relationship managing the cluster name $Nodes = Get-SCOMRelationshipInstance -TargetInstance $VirtualServer | Where-Object {$_.relationshipid -eq $rid.id} | Select-Object -Property SourceObject $NodeNames = $Nodes.SourceObject.DisplayName | Sort-Object FOREACH ($NodeName in $NodeNames) { IF (!($VirtualClusterItem.Node1)) { $VirtualClusterItem | Add-Member -type NoteProperty -Name 'Node1' -Value $NodeName } ELSEIF (!($VirtualClusterItem.Node2)) { $VirtualClusterItem | Add-Member -type NoteProperty -Name 'Node2' -Value $NodeName } ELSEIF (!($VirtualClusterItem.Node3)) { $VirtualClusterItem | Add-Member -type NoteProperty -Name 'Node3' -Value $NodeName } ELSEIF (!($VirtualClusterItem.Node4)) { $VirtualClusterItem | Add-Member -type NoteProperty -Name 'Node4' -Value $NodeName } ELSEIF (!($VirtualClusterItem.Node5)) { $VirtualClusterItem | Add-Member -type NoteProperty -Name 'Node5' -Value $NodeName } ELSEIF (!($VirtualClusterItem.Node6)) { $VirtualClusterItem | Add-Member -type NoteProperty -Name 'Node6' -Value $NodeName } ELSEIF (!($VirtualClusterItem.Node7)) { $VirtualClusterItem | Add-Member -type NoteProperty -Name 'Node7' -Value $NodeName } ELSEIF (!($VirtualClusterItem.Node8)) { $VirtualClusterItem | Add-Member -type NoteProperty -Name 'Node8' -Value $NodeName } } $VirtualClusterItems += $VirtualClusterItem } #Output $VirtualClusterItems | Out-GridView

Leave a Reply

Your email address will not be published. Required fields are marked *