我想要一个 powershell 脚本,为我提供一个 csv 列表,其中包含我正在执行的审核中未禁用的 rdp 用户的 DisplayName 和 MemberOf。这是我到目前为止尝试过的方法,但结果并没有像我希望的那样显示 MemberOf。我想是因为它是一个集合或类似的东西。什么脚本可以正确显示 MemberOf。如果每个 DisplayName 有多条记录,或者甚至每个 Display name 的所有 MemberOf 都合并在一条记录上,我会很高兴。
如果 MemberOf 仅包含 OU 部分,则可获得加分。
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
电流输出
#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
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