Last active
September 6, 2018 07:30
-
-
Save hoetz/9ae40a2e82bef982397d69b23f250b34 to your computer and use it in GitHub Desktop.
Find users from foreign domains in a Active Directory group and output them to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Find users from foreign domains in a Active Directory group and output them to CSV | |
$group=get-adgroup "mygroup" -Properties member | |
$domainController="mydc.company.loc" | |
$fsps = $group.member | where {$_ -like "*foreign*"} | |
$outputUsers = @() | |
foreach ($fsp in $fsps) { | |
$found = $fsp -match 'S-\d-\d-\d+-\d+-\d+-\d+-\w+' | |
if ($found) { | |
$usr = get-aduser $matches[0] -server $domainController -Properties displayname, useraccountcontrol, description, mail | select -Property samaccountname, displayname, useraccountcontrol, description, mail | |
$outputUsers += $usr | |
} | |
} | |
$outputUsers | export-csv -Path "c:\temp\fsp-general.csv" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment