import-Module ActiveDirectory
$groupPath = "D:\Scripts\ADGroupStatus\User\Users_" + (get-date).ToString(‘yyyyMMdd‘) + ".csv"
$Users = Get-ADUser -Filter Properties
$str = "user,samAccountname,memberOf"
$str | Out-File -Encoding utf8 -Append $groupPath
Foreach ( $User in $Users)
{
$str = $User.name+","+$User.samAccountname + ","
foreach ( $memberOf in $User.memberof)
{
$str +$MemberOf.substring(3,$MemberOf.IndexOf(",")-3) || Out-File -Encoding utf8 -Append $groupPath
}
}
原文:https://blog.51cto.com/13804335/2368985