Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 无法查询[adsisearcher]中的受信任域(PowerShell)_Arrays_Powershell_Powershell Remoting - Fatal编程技术网

Arrays 无法查询[adsisearcher]中的受信任域(PowerShell)

Arrays 无法查询[adsisearcher]中的受信任域(PowerShell),arrays,powershell,powershell-remoting,Arrays,Powershell,Powershell Remoting,我想查询[AdiseArcher]以获取受信任和不受信任域中的服务器的一些服务器的OU信息 $session = New-PSSession -ComputerName icvmm02 Invoke-Command -Session $session -ScriptBlock { $compname= (Get-WmiObject "Win32_Computersystem" -namespace "root\CIMV2" -computername $comp).name $searcher

我想查询[AdiseArcher]以获取受信任和不受信任域中的服务器的一些服务器的OU信息

$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时传递$cred=get凭据,但在运行

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

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
使用“0”参数调用“FindOne”时出现异常:“发生操作错误。
"
第1行字符:27

+$ou=$searcher.FindOne我不知道原因,但ADSI接口在远程会话中无法工作。我甚至无法在我的域中获取计算机域的DN。我可以让它在本地运行,但不能远程运行:

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

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

我不知道原因,但ADSI接口在远程会话中无法工作。我甚至无法在我的域中获取计算机域的DN。我可以让它在本地运行,但不能远程运行:

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

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

看起来FindOne方法调用有问题-您可以通过此方法了解有关$searcher对象的更多信息

$searcher | gm
findOne方法应该有一个参数列表

不过,我刚刚在型号上试用过:

[adsisearcher] | gm | sort name

而且没有FindOne方法-你确定这是AdiseArcher的方法吗?

看起来FindOne方法调用有问题-你可以通过这个找到更多关于$searcher对象的信息

$searcher | gm
findOne方法应该有一个参数列表

不过,我刚刚在型号上试用过:

[adsisearcher] | gm | sort name

没有FindOne方法-你确定这是AdiseArcher的方法吗?

嗨@shay levy谢谢你的回复,你能告诉我其他解决方法吗?。感谢您的回复,如果您找到一些可以帮助我的解决方法,请务必告诉我。谢谢很好的一天!嗨@shay levy我正在使用任务广告命令提取OU信息,但是我遇到了一些错误。你能帮我吗嗨@shay levy谢谢你的回复,你能告诉我其他的解决方法吗?。感谢您的回复,如果您找到一些可以帮助我的解决方法,请务必告诉我。谢谢很好的一天!嗨@shay levy我正在使用任务广告命令提取OU信息,但是我遇到了一些错误,你能帮我吗