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

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

相关文章

Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...
Windows文件操作基础代码 Windows下对文件进行操作使用的一段...
Winpcap基础代码 使用Winpcap进行网络数据的截获和发送都需要...
使用vbs脚本进行批量编码转换 最近需要使用SourceInsight查看...