1

我在 PowerShell 2.0 中使用Get-QADUser.DirectoryEntry.FirstName进行多个 LDAP 查询并返回字符串。这些多次调用很慢。我怎样才能只进行一次Get-QADUser LDAP 查询并从选择的属性中创建字符串。

例子:

    ADD-PSSnapin Quest.Activeroles.ADManagement
    $searchDomainFrom = 'domain.net/OUPath/Users'
    $user = UserName

    $FirstName = (Get-QADUser -SearchRoot $searchDomainFrom $user).DirectoryEntry.FirstName
    $LastName = (Get-QADUser -SearchRoot $searchDomainFrom $user).DirectoryEntry.LastName
    $Email = (Get-QADUser -SearchRoot $searchDomainFrom $user).DirectoryEntry.Email
    $Supervisor = (Get-QADUser -SearchRoot $searchDomainFrom $user).DirectoryEntry.Manager
    $OfficeLocation = (Get-QADUser -SearchRoot $searchDomainFrom $user).DirectoryEntry.Office
    $PhoneNumber = (Get-QADUser -SearchRoot $searchDomainFrom $user).DirectoryEntry.PhoneNumber
4

1 回答 1

0

只需进行一次查询,然后从第一次返回的对象中获取您的字符串。

$Current = Get-QADUser -SearchRoot $searchDomainFrom $user
$FirstName = $Current.DirectoryEntry.FirstName
$LastName = $Current.DirectoryEntry.LastName
$Email = $Current.DirectoryEntry.Email
$Supervisor = $Current.DirectoryEntry.Manager
$OfficeLocation = $Current.DirectoryEntry.Office
$PhoneNumber = $Current.DirectoryEntry.PhoneNumber
于 2014-03-24T15:18:32.610 回答