##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
}
}
dotnVo
September 26, 2024, 12:39pm
2
I’m moving this to the PowerShell help category. What’s the question and what are you trying to accomplish?
Looking at this line of code:
Needs to be updated to:
$ADusermems = Get-ADUser $inuser -Properties memberof | select -ExpandProperty memberof
grey0ut
September 26, 2024, 10:18pm
4
I don’t know that it has to. They both do the same thing just with different syntax.
You’re right… It works fine without expanding…Thanks
grey0ut
September 27, 2024, 12:02am
6
Well to be clear that’s what the dot syntax does: print a property’s value. Select-Object -ExpandProperty is doing the same thing.
It’s just two different ways to do the same thing.
1 Like
system
Closed
October 27, 2024, 12:02am
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.