-
-
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
This file contains 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
#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