##ADuser_displayname_Memberof
$path = “C:\Temp\Scripts\ADUserMemberof”
$Users = Get-Content “$path\Users.txt”
$FileTime = get-date -Format “yyyyMMdd-hhmmss”
$Output = “$path\UserMember0f-$FileTime.csv”
$header = “User,Group”
Add-Content $output $header
foreach($inuser in $Users)
{
if($inuser.Length -gt 20){ $inuser = $inuser.Substring(0,20) }
try
{
$Displayname = (Get-ADUser $inuser -Properties Displayname).displayname
$ADusermems = (Get-ADUser $inuser -Properties memberof).memberof
foreach($ADusermem in $ADusermems)
{
$ADgroup = ($ADusermem.Split(“,”)[0]).Split(“=”)[1]
$data = $inuser + “,” + $Displayname + “,” + $ADgroup
Add-Content $output $data
}
}
catch
{
Write-Host $inuser
$data = $inuser + “,UserNotAvailable”
Add-Content $output $data
}
}