无法查询[adsisearcher对于信任域(PowerShell中) [英] Unable to query [adsisearcher] for trusted domains (PowerShell)

查看:285
本文介绍了无法查询[adsisearcher对于信任域(PowerShell中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询[adsisearcher]让我在服务器的几个服务器的OU信息条放;非信任域。

I wanted to query [adsisearcher] to get me the OU info for a few servers for servers in trusted & non trusted domains.

$session = New-PSSession -ComputerName icvmm02

Invoke-Command -Session $session -ScriptBlock {
$compname= (Get-WmiObject "Win32_Computersystem" -namespace "root\CIMV2" -computername $comp).name
$searcher = [adsisearcher]"(&(ObjectCategory=computer)(Name=$compname))"
$ou= $searcher.FindOne() | Select-Object path
$serverou = $ou.path
}
$adou= (Invoke-Command -Session $session  -ScriptBlock { $serverou })
Get-PSSession | Remove-PSSession

在受信任域中的服务器即时通讯传递$名气=获取凭据在创建的PSSession,但是当我运行

for servers in trusted domains im passing a $cred = get credentials while creating a pssession, but when i run

$compname= (Get-WmiObject "Win32_Computersystem" -namespace "root\CIMV2" -computername $comp).name
$searcher = [adsisearcher]"(&(ObjectCategory=computer)(Name=$compname))"
$ou= $searcher.FindOne() | Select-Object path

它给了我一个错误

it gives me an error as

Exception calling "FindOne" with "0" argument(s): "An operations error occurred.
"
At line:1 char:27
+     $ou= $searcher.FindOne <<<< () | Select-Object path
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
$serverou = $ou.path

能有人帮我分拣了这一点。

Could some one please help me in sorting this out.

推荐答案

我不知道原因,但ADSI接口只是没有在远程会话中运行。我甚至不能得到一台电脑在我的域中的域的DN。我能得到这个在本地而不是远程运行:

I don't the cause but the ADSI interface just doesn't work in remote sessions. I can't even get the DN of the domain of a computer in my domain. I can get this to run locally but not remotely:

icm { ([adsi]"").distinguishedName }  #works

icm -Session $s -ScriptBlock { ([adsi]"").distinguishedName } #doesn't work

这篇关于无法查询[adsisearcher对于信任域(PowerShell中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆