微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

windows-server-2008 – 从不属于域成员的Windows主机查询PowerShell中的Active Directory

如何使用Power Shell [adsisearcher]查询我不是其成员的域?通常我会做这样的事情:
$myAdsi = [adsisearcher]""
$myAdsi.SearchRoot = [adsi]"LDAP://dc=corp,dc=mycompany,dc=com"
$myAdsi.Filter = "objectCategory=computer"

$res = $myAdsi.FindAll()

如果我在我的域中的主机上运行此代码段,我会得到预期的结果.但是,如果我从具有网络访问权限的计算机(通过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

这是有点预期的,因为我没有向[adsisearcher]提供任何类型的凭证,告诉它如何进行身份验证.我的问题是:如何让[adsisearcher]知道我想对我不是其中一员的域进行身份验证?

编辑了我的上一个回复.对不起,我花了一段时间才回复你.以下是从 http://powershell.com/cs/blogs/ebookv2/archive/2012/03/26/chapter-19-user-management.aspx无耻地复制:

[ADSI]是DirectoryServices.DirectoryEntry .NET类型的快捷方式.这就是为什么你也可以这样设置以前的连接:

$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

你是对的,这是一个身份验证问题,即使我希望错误信息更准确地反映出来.这应该对你有帮助.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐