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

前端之家收集整理的这篇文章主要介绍了windows-server-2008 – 从不属于域成员的Windows主机查询PowerShell中的Active Directory前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用Power Shell [adsisearcher]查询我不是其成员的域?通常我会做这样的事情:
  1. $myAdsi = [adsisearcher]""
  2. $myAdsi.SearchRoot = [adsi]"LDAP://dc=corp,dc=mycompany,dc=com"
  3. $myAdsi.Filter = "objectCategory=computer"
  4.  
  5. $res = $myAdsi.FindAll()

如果我在我的域中的主机上运行此代码段,我会得到预期的结果.但是,如果我从具有网络访问权限的计算机(通过L2L VPN)运行此命令,我会收到错误消息:

  1. Exception calling "FindAll" with "0" argument(s): "The specified domain either does not exist or could not be contacted.
  2. "
  3. At line:11 char:33
  4. + $adComputers = $searcher.FindAll <<<< ()
  5. + CategoryInfo : NotSpecified: (:) [],MethodInvocationException
  6. + FullyQualifiedErrorId : DotNetMethodException

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

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

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

  1. $domain = [DirectoryServices.DirectoryEntry]""
  2. $domain
  3. distinguishedName
  4. -----------------
  5. {DC=scriptinternals,DC=technet}

因此,请尝试将此凭据提供给另一个域:

  1. $domain = new-object DirectoryServices.DirectoryEntry("LDAP://10.10.10.1","domain\user","secret")
  2. $domain.name
  3. scriptinternals
  4. $domain.distinguishedName
  5. DC=scriptinternals,DC=technet

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

猜你在找的Windows相关文章