Blog
By Pete Zerger on 10/18/2010 11:33:05 PM • Rank (2658) • Views 2802
0

0

There was forum discussion this morning asking if a Powershell script exists that would enumerate all the members of a OpsMgr 2007 group. Here are the links for those old scripts (from 2007)

Here is another script that does the same thing pretty simply. It enumerates all of the OpsMgr groups for which a computer is a member. If the groups is empty, the script will report so.

Instructions for Use

Cut-and-paste into Notepad and save with a .ps1 extension. Run from an OpsMgr Command Shell instance.

Sample Script

function GetDisplayName($object)
{
 
$displayName = [System.String]::Empty
 
if(($object.DisplayName -eq $null) -or ($object.DisplayName.Length -eq 0))
{
$displayName = $object.Name;
}
else
{
$displayName = $object.DisplayName;
}
$displayName;
}
 
$mg = (Get-ManagementGroupConnection).ManagementGroup
$groups = $mg.GetRootPartialMonitoringObjectGroups() | sort DisplayName
 
foreach($group in $groups)
{
 
Write-Host $group.DisplayName
 
$groupMembers =
$group.GetRelatedPartialMonitoringObjects([Microsoft.EnterpriseManagement.Common.TraversalDepth]::OneLevel);
 
if($groupMembers.Count -eq 0)
{
Write-Host "The group is empty"
}
else
{
$groupMembers | Select-Object DisplayName,Path,@{name="Type";expression={foreach-object {GetDisplayName $_.GetLeastDerivedNonAbstractMonitoringClass()}}} | sort DisplayName | ft
}
 
Write-Host
}
Comments (1) - Comment RSS
Andreas Zuckerhut wrote: on Dec 11, 2009 06:06 PM
Thanks for that Pete


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/ya8rrpx

Top Contributors
Featured Members
Pete Zerger
Points: 65622
Level: System Center Expert
Tommy Gunn
Points: 42748
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Stefan Koell
Points: 28999
Level: System Center Expert
Andreas Zuckerhut
Points: 27734
Level: System Center Expert