Active-Directory

用於從域中提取所有使用者的 Powershell 命令

  • October 12, 2015

Get-ADUser -SearchBase "dc=contoso,dc=local" -filter * -properties Name, Surname, samAccountName, Enabled, PasswordNeverExpires, PasswordExpired, PasswordLastSet, MemberOf | Select Name, Surname, SamAccountName, Enabled, PasswordExpired, MemberOf | Export-Csv C:\temp\expired3.csv

我需要域中具有這些屬性的所有使用者的列表,問題出在MemberOf屬性上。而不是得到他們所屬的團體,我只得到Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

您可以使用Select @{name=”MemberOf”;expression={$_.memberof -join “;”}}將多值屬性“MemberOf”導出到 CSV:

Get-ADUser -SearchBase "dc=contoso,dc=local" -filter * -properties Name, Surname, samAccountName, Enabled, PasswordNeverExpires, PasswordExpired, PasswordLastSet, MemberOf | `
       Select Name, Surname, SamAccountName, Enabled, PasswordExpired, @{name=”MemberOf”;expression={$_.memberof -join “;”}} | `
           Export-Csv C:\temp\expired3.csv

引用自:https://serverfault.com/questions/728314