我如何使用PowerShell [adsisearcher]查询我不属于的成员? 通常我会做这样的事情:
$myAdsi = [adsisearcher]"" $myAdsi.SearchRoot = [adsi]"LDAP://dc=corp,dc=mycompany,dc=com" $myAdsi.Filter = "objectCategory=computer" $res = $myAdsi.FindAll()
如果我在我的域中的主机上运行此片段,我会得到预期的结果。 但是,如果我从一台有networking访问权的计算机(通过L2L VPN)运行这个服务,我得到的错误是:
Exception calling "FindAll" with "0" argument(s): "The specified domain either does not exist or could not be contacted. " At line:11 char:33 + $adComputers = $searcher.FindAll <<<< () + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
这是有点期待,因为我没有提供任何forms的[adsisearcher]凭据,将告诉它如何进行身份validation。 我的问题是:我怎么让[adsisearcher]知道我想对一个我不是其中成员的域进行身份validation?
编辑了我的最后一个答复。 对不起,我花了一段时间才find你。 以下是无耻复制从http://powershell.com/cs/blogs/ebookv2/archive/2012/03/26/chapter-19-user-management.aspx :
[ADSI]是DirectoryServices.DirectoryEntry .NETtypes的快捷方式。 这就是为什么你可以这样设置以前的连接:
$domain = [DirectoryServices.DirectoryEntry]"" $domain distinguishedName ----------------- {DC=scriptinternals,DC=technet}
所以试试这个提供凭据到另一个域:
$domain = new-object DirectoryServices.DirectoryEntry("LDAP://10.10.10.1","domain\user", "secret") $domain.name scriptinternals $domain.distinguishedName DC=scriptinternals,DC=technet
你是对的,这是一个authentication问题,即使我希望错误信息更准确地反映这一点。 这应该对你有所帮助