none
Members of groups from different domain RRS feed

  • Question

  • Hi team,

    Looking for a powershell script, which pulls the member of the security group from the list. However, its not sure which domain the group is from. was wondering how to loop it under to search in all the domains for the groups porvided in the txt file.

    Get-content C:\groups.txt |
    ForEach-Object{
    $groupname = $_
    Get-ADGroupMember $groupname -Recursive |
    Where-Object{ $_.objectClass -eq 'User' } |
    Select-Object *, @{ n = 'GroupName'; e = { $groupname } }
    } |
    Select-Object GroupName, samAccountName | 
    Export-csv "C:\output.csv" -NoTypeInformation

    The above scripts failed for group which are in different then the logged on domain.


    Tuesday, November 26, 2019 3:23 PM

All replies

  • You may use a nested loop where you loop in the outer loop through the available domains and in the inner loop through the available groups inside this domains.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, November 26, 2019 8:04 PM