How to obtain the computer names inside a group in active directory with powershell?

Juan Felipe Lopez Vasquez 1 Reputation point
2022-06-03T21:56:47.227+00:00

HI guys, maybe you can help me with this question, i need to get a list of computer inside an especific group in the active directory, but none of the scripts i've tried, work.

Example:

Get-ADPrincipalGroupMembership -Identity "GRP_NAC_POLITICAS" | export-csv 'C:\Users\svc1yol\Documents\grupitos.csv'

i execute it, and nothing happen.

id be really thankful if anybody can help me.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-06-04T01:40:18.48+00:00

    The cmdlet you should be using is Get-ADGroupMember.

    The Get-ADPrincipalGroupMembership will get you the groups in which an AD object is a member.

    0 comments No comments

  2. Newbie Jones 1,386 Reputation points
    2022-06-06T12:22:04.393+00:00

    If you only want computers, you can include a client side filter against the objectClass

    Get-ADGroupMember testGroup | Where-Object {$_.objectClass -eq 'Computer'}
    
    0 comments No comments

  3. Limitless Technology 39,926 Reputation points
    2022-06-08T07:16:04.223+00:00

    Hi there,

    The below script might help you in exporting the data to excel.

    Get-ADComputer -Filter * -Properties * | Where-Object {
    $.MemberOf -like "*SOME OF THE GROUP NAME*"
    } | Select-Object Name,OperatingSystem,@{
    N="Grupper";E={
    $groups=""
    $
    .MemberOf | get-adgroup | Select-Object Name | ForEach-Object {$groups+=$_.Name+","}
    $groups -replace ",$",""
    }
    } | Export-csv "C:\temp\file.csv"


    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.