【发布时间】:2019-09-25 19:26:28
【问题描述】:
这里是半新手。我正在尝试使用 Get-ADUser 以特定顺序显示用户信息。 Get-ADUser 属性列表的默认顺序似乎不符合我们的需求。到目前为止我有;
$Users = Get-ADUser -Filter * -SearchBase $treeview.SelectedNode.Name -Properties Name, CN, SamAccountName, DisplayName, sn, GivenName, Initials, `
OtherName, mail, EmailAddress, EmployeeNumber, Company, StreetAddress, POBox, City, State, PostalCode, Country, Department, HomePhone, `
telephoneNumber, OfficePhone, MobilePhone, Fax, info, physicalDeliveryOfficeName, Title, Office, EmployeeID, Description, DistinguishedName, `
CanonicalName, AccountExpirationDate, Created, Enabled, HomeDirectory, HomeDrive, HomePage, LastLogonDate, LockedOut, logonCount, Manager, `
Modified, msNPAllowDialin, ObjectClass, objectSid, PasswordLastSet, UserPrincipalName, whenChanged |
Select-Object Name, CN, SamAccountName, `
DisplayName, sn, GivenName, Initials, OtherName, mail, EmailAddress, EmployeeNumber, Company, StreetAddress, POBox, City, State, PostalCode, `
Country, Department, HomePhone, telephoneNumber, OfficePhone, MobilePhone, Fax, info, physicalDeliveryOfficeName, Title, Office, EmployeeID, `
Description, DistinguishedName, CanonicalName, AccountExpirationDate, Created, Enabled, HomeDirectory, HomeDrive, HomePage, LastLogonDate, `
LockedOut, logonCount, Manager, Modified, msNPAllowDialin, ObjectClass, objectSid, PasswordLastSet, UserPrincipalName, whenChanged `
| Export-Csv -NoTypeInformation -Path $LogFile
虽然下面的代码运行得相当快(1758 位用户需要 4 秒),但这似乎有点冗长,我相信还有更有效的方法。我已经研究过哈希表,但即便如此,只要付出以上两倍的努力。
【问题讨论】:
-
将您的
-Properties Long, List, of, Stuff更改为'-Properties *` 以获取所有道具。然后建立你的Select-Object列表。我会使用一个数组来保存属性列表,但这不是必需的。 -
@Lee_Dailey 我不使用 '-Properties *' 的唯一原因,对于 1758 位用户来说,使用 * 时从 4 秒到 24 秒。
-
啊!这就说得通了。 [grin] 所以...将道具添加到列表中,并在您的两个位置使用该列表。
标签: powershell hashtable export-to-csv