Friday, 23 June 2023

PowerShell : Get membership info for a computer Object.

 PowerShell : Get membership info for a computer Object.



File Format :



$Computers= Get-Content C:\Temp\ADComputer.txt

$output = foreach($Computer in $Computers)

{

    $groups = Get-ADPrincipalGroupMembership (Get-ADComputer $Computer) | select-object name


     foreach($group in $groups)

    {

        [PSCustomObject]@{

            ComputerName  = $Computer

            Group = $group.Name

        }

    }

}

 $output   | Export-Csv c:\temp\ADComputer.csv -


No comments:

Post a Comment