0

I want a powershell script to give me a csv list of the DisplayName and MemberOf for rdp users that are not disabled for an audit I'm doing. Here is what I've tried so far, but the results aren't showing the MemberOf as I hoped. I think becase it's a collection or something. What would be a working script that would show MemberOf correctly. I'd be happy if it was multiple records per DisplayName, or even all MemberOf combined on one record per Display name.

Bonus points if the MemberOf only has the OU part.

Get-ADUser -Filter {(msTSManagingLS -like '*' -and msTSLicenseVersion -like '*') -or (terminalServer -like '*')} -Properties * | Where-Object {$_.Enabled -like “true”} | Select-Object -Property DisplayName, memberof |export-csv -Path c:\spla\out.csv 

Current Output

#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser "DisplayName","memberof" ,"Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Ben01","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Ben02","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Ben04","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Ben05","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Ben06","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Ben07","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Ben03","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Ben08","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "ralliance04","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "towncenter05","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Shannon","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "towncenter04","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Shelley","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "towncenter03","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Jessica","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Randi","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" "Kristin","Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" 

1 Answer 1

1
 Get-ADUser -Filter {(msTSManagingLS -like '*' -and msTSLicenseVersion -like '*') -or (terminalServer -like '*')} ` -Properties DisplayName, MemberOf | Where-Object {$_.Enabled -like "true"} ` | Select-Object -Property DisplayName, @{n='MemberOf'; e= { ( $_.MemberOf | % { (Get-ADObject $_).Name }) -Join "|" }} ` | Sort-Object -Property DisplayName | export-csv "c:\spla\out.csv" -NoTypeInformation -Encoding UTF8 
1
  • This appears to work exactly how I wanted. Thank you! Commented Oct 3, 2019 at 19:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.