Maxim's profileOpsMgr 2007 NotesBlogLists Tools Help

Blog


    February 10

    Determine a computer’s group with Powershell

    If your OpsMgr environment has a complex group structure with a huge amount of groups and subgroups, it’s going to be rather difficult to determine a group membership of the particular computer. Here is a small powershell script that allows you to find out a computer’s membership very quickly.

    Usage is clear, just pass a computer FQDN as a parameter.

    >C:\GetGroupsThatContainComputer.ps1 <computerFQDN>

    like >C:\GetGroupsThatContainComputer.ps1 hydra.contoso.com

    As result you will get a list of all groups that contain computer hydra.contoso.com

    Here is full source code of GetGroupsThatContainComputer.ps1 file:

     

    param($computerFQDN)

    function GetGroupNames($computerFQDN)
    {
    $containmentRel = Get-RelationshipClass -name:'Microsoft.SystemCenter.InstanceGroupContainsEntities'

    $computerClass = Get-MonitoringClass -name:"Microsoft.Windows.Computer"

    $criteria = [string]::Format("PrincipalName = '{0}'",$computerFQDN)

    $computer = Get-MonitoringObject -monitoringClass:$computerClass -criteria:$criteria

    $relatedObjects = $computer.GetMonitoringRelationshipObjectsWhereTarget($containmentRel,[Microsoft.EnterpriseManagement.Configuration.DerivedClassTraversalDepth]::Recursive,[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive)

    foreach($group in $relatedObjects)
    {
    $group.SourceMonitoringObject.DisplayName
    }

    }

    GetGroupNames $computerFQDN

     

    Enjoy!


    This posting is provided AS IS with no warranties. Use it at your own risk.

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://maxim-ua.spaces.live.com/blog/cns!9C26C04B756ADA31!138.trak
    Weblogs that reference this entry
    • None