none
Getting users from nested groups. RRS feed

  • Question

  • I have a script that looks at a group and puts the users in an array $Users and loops through and lists them on the screen.  Works great.

    Clear-Host
     
    $ADGroup = "Intranet Users"
    Write-Host "Reading AD users from" $ADGroup
    $Users = Get-ADGroupMember $ADGroup | Get-ADUser -Properties * | Select Name,Mail,Department,Enabled

    foreach ($user in $Users) {
      Write-Host $User.Name, $User.Mail, $User.Department, $User.Enabled
    }

    I want to change this to use a group that has several other groups as members that contain users. Example Group:  "All Company Users" that contains "All Illinois Users", "All Florida Users", etc as well as some users.

    I just want the username, email, department and if they are enabled.

    I need them in an array like $User so I can loop through and compare to another source.

    Thanks.

    Wednesday, January 2, 2019 9:38 PM

Answers

  • There are numerous script in the Gallery that will do this. You can also just use "Get-AdGroupMember".

    Get-AdGroupMember testgrp2 -Recursive

    help Get-AdGroupMember -online


    \_(ツ)_/

    Wednesday, January 2, 2019 9:50 PM

All replies

  • There are numerous script in the Gallery that will do this. You can also just use "Get-AdGroupMember".

    Get-AdGroupMember testgrp2 -Recursive

    help Get-AdGroupMember -online


    \_(ツ)_/

    Wednesday, January 2, 2019 9:50 PM
  • Richard,  The -Recursive worked great.

    Thanks much.

    Thursday, January 3, 2019 3:22 PM