Skip to content

Instantly share code, notes, and snippets.

@funkwhatyouheard
funkwhatyouheard / groupenumeration.ps1
Last active July 9, 2020 19:30 — forked from joswr1ght/groupenumeration.ps1
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])