0

使用 PowerShell,我正在尝试使用该属性获取Get-ADUserADUserLdapFilter帐户employeeid。我正在使用域的 GC 服务器作为源服务器以获得更快的结果。但是,我没有获得匹配的 ADUser 帐户。但是,我可以使用DirectorySearcher对象检索结果。请参考下面尝试过的代码片段,

###

#1 DirectorySearcher

$empid = "123456"

$ldapcn = "GC://dc=mydomain,dc=net"

$ldapfilter = "(&(ObjectCategory=Person)(objectclass=user)(employeeid=" + $empid + "))"

$objent = new-object System.DirectoryServices.DirectoryEntry($ldapcn)
$objsearch = new-object System.DirectoryServices.DirectorySearcher
$objsearch.SearchRoot = $objent
$objsearch.SearchScope = "subtree"
$objsearch.Filter = $ldapfilter
$objsearch.pagesize = 1000

$properties = "employeeid","givenname","sn","samaccountname"

$objsearch.propertiestoload.addrange($properties)
$results = $objsearch.Findall()

# Working
# $results contains matching user records

######################################################

#2 Get-ADUser

$empid = "123456"

$Server_AD_GC = (Get-ADDomainController -Server mydomain.net | select -exp hostname) + ":3268"
$ldapfilter = "(&(ObjectCategory=Person)(objectclass=user)(employeeid=" + $empid + "))"

$results = Get-ADUser -LdapFilter $ldapfilter -Properties employeeid, givenname, sn, samaccountname -Server $Server_AD_GC

# NOT WORKING!
# $results DOES NOT CONTAIN matching user records

我在这里想念什么?!任何帮助将不胜感激。


更新 1

我刚刚使用下面的代码验证了部分属性集 (PAS),但没有employeeid看到包含在列表中

$Domain = "mydomain.net"
# $schemaNamingContext =  "cn=Schema,cn=Configuration,dc=mydomain,dc=net"
$schemaNamingContext = (Get-ADRootDSE -Server $Domain).SchemaNamingContext
Get-ADObject -SearchBase $schemaNamingContext -LDAPFilter "(isMemberOfPartialAttributeSet=TRUE)" -Properties ldapDisplayName | Select ldapDisplayName | sort ldapDisplayName

有关更多背景信息,我正在运行“DirectorySearcher”代码块来搜索源代码并从加入受信任域mydomain.net的服务器运行它,例如,来自不同的森林。重要的是,调用 trust domain的 PAS CONTAINS。但是,如前所述,无法获取记录。W2012R2mycaller.netmycaller.net employeeidGet-ADUser

下面是在不同环境下观察到的结果截图,

获取 ADuser-and-DirectorySearcher-Results

现在,如果不是为了解决方案,如果至少有人能够重现这种行为,我会很高兴。

询问:

  1. 在我的例子中,

    DirectorySearcher$ldapcn = "GC://DC=mydomain,DC=net"

    对比

    Get-ADUser$Server_AD_GC = (Get-ADDomainController -Server $Domain | select -exp hostname) + ":3268"

    我希望两者都以类似的方式工作。我看到我没有为 指定主机,DirectorySearcher但为Get-ADUser. 这是要调查的事情吗?

4

0 回答 0