multiple lines for each group membership in Active Directory

Hi everyone,

I have this script, that collects data from each user:

Get-ADUser -Filter * -Properties Name,memberof, SamAccountName,Displayname,UserPrincipalName,Description,ObjectClass,ObjectGUID,passwordlastset,passwordneverexpires,LastLogonDate,DistinguishedName,Enabled,whenCreated,SID,badpwdcount,msDS-UserPasswordExpiryTimeComputed | 
Select-Object -Property Name,@{ l="GroupMembership"; e={$_.memberof -join ";" } },SamAccountName,Displayname,UserPrincipalName,Description,ObjectClass,ObjectGUID,passwordlastset,passwordneverexpires,LastLogonDate,DistinguishedName,Enabled,whenCreated,SID,badpwdcount,@{Name="PasswordExpirationDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}| 
Sort-Object -Property Name|
Export-csv -path "c:\temp\extract.csv" -NoType

this gives me each group membership in the same field, separated by a comma. is there any way i can print one line with user data per group membership?

i tried using the ´-d delimiter to print out a new line (at least in excel) but without any luck

Hey,
Had a quick play in our environment looks like you were pretty close. Simple solution is replace your join of “;” with “`r`n” and you might get the result you are after. Hope it helps

Get-ADUser -Filter * -Properties Name,memberof, SamAccountName,Displayname,UserPrincipalName,Description,ObjectClass,ObjectGUID,passwordlastset,passwordneverexpires,LastLogonDate,DistinguishedName,Enabled,whenCreated,SID,badpwdcount,msDS-UserPasswordExpiryTimeComputed |`
Select-Object -Property Name,@{ l="GroupMembership"; e={$_.memberof -join "`r`n" } },SamAccountName,Displayname,UserPrincipalName,Description,ObjectClass,ObjectGUID,passwordlastset,passwordneverexpires,LastLogonDate,DistinguishedName,Enabled,whenCreated,SID,badpwdcount,@{Name="PasswordExpirationDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}|`
Sort-Object -Property Name |`
Export-csv -path "C:\temp\extract.csv" -NoType