加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-server-2008 – 从不属于域成员的Windows主机查询PowerS

发布时间:2020-12-13 23:43:40 所属栏目:Windows 来源:网络整理
导读:如何使用Power Shell [adsisearcher]查询我不是其成员的域?通常我会做这样的事情: $myAdsi = [adsisearcher]""$myAdsi.SearchRoot = [adsi]"LDAP://dc=corp,dc=mycompany,dc=com"$myAdsi.Filter = "objectCategory=computer"$res = $myAdsi.FindAll() 如果
如何使用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","domainuser","secret")
$domain.name
scriptinternals
$domain.distinguishedName
DC=scriptinternals,DC=technet

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读