Skip to content

Instantly share code, notes, and snippets.

@funkwhatyouheard
Forked from joswr1ght/groupenumeration.ps1
Last active July 9, 2020 19:30
Show Gist options
  • Save funkwhatyouheard/514591a31a1ab63029d1899fcc2edabc to your computer and use it in GitHub Desktop.
Save funkwhatyouheard/514591a31a1ab63029d1899fcc2edabc to your computer and use it in GitHub Desktop.
Create a Collection of Files for Windows Domain Groups with User Members in Each File
#intent is to eventually update DPAT to accept these other fields
#$properties = @('UserPrincipalName';'Enabled';'PasswordLastSet';'PasswordExpired';'PasswordNeverExpires';'whenCreated';'whenChanged')
$properties = @('UserPrincipalName')
foreach($group in (get-adgroup -filter *)) {
$UPNs = @()
$UPNs = Get-ADGroupMember -Recursive $group.samaccountname -ea SilentlyContinue | get-aduser -properties $properties -ea silentlycontinue | Select-Object -ExpandProperty $properties -ea silentlycontinue
if($UPNs.Count -ge 1){
$members = @()
foreach($UPN in $UPNs){
$members += ("{0}\{1}" -f $UPN.split("@")[1], $UPN.split("@")[0])
}
Out-File -InputObject $members -FilePath ("{0}.txt" -f $group.samaccountname) -Encoding ASCII
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment