O R G A N I C / F E R T I L I Z E R: listing the group membership of a computer in opsmgr

Jan 5, 2010

listing the group membership of a computer in opsmgr

inside of operations manager, groups are utilized in a variety of ways.  at the core of a group, the definition is still the same.  you use it to “group” things together.  you can use groups to define the membership of console scopes, notifications, overrides, views, etc.

since it’s heavily utilized in operations manager, sometimes, you’ll want a way to get that information back out.  a friend on twitter asked the question if it was possible to retrieve the membership list of all groups a computer belongs to.  to begin with, the boris yanushpolsky blogged about doing this very thing over 2 years ago.

by then, i was well into writing my own little thing.  anyway, it’s a work in progress.  i don’t know if it’s actually working as designed yet but so far it appears to be pulling back the expected groups of the one computer name i have tested it with.  if you’d like to give it a go, here’s the script:

param (
[string]$myComputer
)

# Function
function GetOpsMgrGroups {

Write-Host "`nRetrieving groups for $myComputer..."
$myGroups = Get-MonitoringObject | Where-Object {
$_ -like "*group*" -or $_.pathname -like "*group*"
} | Sort-Object -Unique

$myGroups | ForEach-Object {
$myCounter = 0
$myCurrentGroup = $_.displayname
$_.GetRelatedMonitoringObjects() | ForEach-Object {
if ($_.displayname -like "*$myComputer*") {
if ($myCounter -eq 0) {
Write-Host " $myCurrentGroup"
}
$myCounter += 1
}
}
}

}

GetOpsMgrGroups ($myComputer)

just run it with one parameter – the computer you’re interested in.  if you don’t have the opsmgr console loaded but want to use opsmgr scripts, follow the advice in this blog post.

while i’m at it, i ran across this post this morning which will speed up your slow tab expansions in the opsmgr command shell. 

 

drop some comments!  interested in hearing if this works for you.