skip to Main Content

I have been using the following command to pull the list of membership for a given machinename:

Get-ADPrincipalGroupMembership -Identity (Get-ADComputer <MACHINENAME>) 
| select-object name | Out-File C:mydirMemberShip.csv

The membership identifies software associated to a machine such as Adobe Acrobat Pro, MS Project, etc. Sometimes the software is associated but not actually installed which is why I use the query to validate this information against another list. I am trying to run a query to pull the membership for a list of assets in a text file and export with the name of each computer and the membership for each as well. Maybe get it to display something like the following:

NAME            NAME
-----------     -------------
<MACHINENAME1>  ADOBE ACROBAT PRO
                MS PROJECT STD
                MS VISIO PRO

<MACHINENAME2>  ADOBE ACROBAT PRO
                ADOBE PHOTOSHOP

I have tried the following but I get a few errors:

$computers = Get-Content .computers.txt 
Get-ADPrincipalGroupMembership ForEach ($computer in $computers) 
{Get-ADComputer $computer} | select-object operatingSystem, name | 
Out-Gridview

Any help or guidance would be greatly appreciated. Thank you.

2

Answers


  1. $computers = Get-Content .computers.txt 
    
    $results = foreach ( $computer in $computers ) {
    
            $adcomputerproperties = get-adcomputer -Identity $computer -Properties *
            Get-ADPrincipalGroupMembership -Identity $adcomputerproperties.DistinguishedName 
            | select @{n="Computername";e={ $computer}},Name,@{n="OperatingSystem"; e={ $adcomputerproperties.OperatingSystem}}  } 
    
    
    $results | Out-GridView
    
    Login or Signup to reply.
  2. You could do something like this. You could put it in a script, function or whatever.

    $results = New-Object -TypeName System.Collections.ArrayList
    $computers = Get-Content .computers.txt
    
    $computers | ForEach-Object {
        $ComputerObject = Get-ADComputer $_
        $obj = @{
            Computername = $_
            OS = $ComputerObject.OperatingSystem
        }
    
        $obj.Memberships = Get-ADPrincipalGroupMembership -Identity $ComputerObject | select-object name 
    
        $results.Add($obj) | Out-Null
    }
    
    return $results
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search