2014-10-17 122 views
1

我想使用下面的脚本从不同的森林运行portqry,但我收到路径无法找到错误。而从访问网络共享文件我可以手动与无的问题从远程域访问从unc路径Acess exe

#找林名称

$domain = "spos02600287.test.net" 
$contextType = [system.directoryservices.activedirectory.Directorycontexttype]::Domain 
$domain ="$domain" 
$domainContext = new-object system.directoryservices.ActiveDirectory.DirectoryContext @($contextType,$domain) 
#Query the Forest and PDC Role Emulator 
$Server = [system.DirectoryServices.Activedirectory.Domain]::GetDomain($domaincontext) 
$passwords = "newtemp123" 
$user = "$domain\Administrator" 
$password = $Passwords | ConvertTo-SecureString -AsPlainText -Force 
$creds = New-Object System.Management.Automation.PSCredential -argument $user, $password 

$PDC =$server.Name 
foreach ($serv in $PDC){ 

$Server = "d.root-servers.net" 
$Port = "53" 

Invoke-Command -ComputerName $serv -Credential $creds -ScriptBlock {\\10.28.64.15\EXE\portqry.exe -n $Server -e $Port -p UDP }} 
+0

的问题是由刚刚加入-authentication的CredSSP在调用命令行像下面解决解决Invoke-Command -ComputerName $ serv -Credential $ creds -authentication credssp -ScriptBlock {} – user3130604 2014-10-20 18:17:20

回答

0

遇到什么样子著名PowerShell的双跳的问题。 基本上,通过Invoke-command进行远程处理时,您无法访问远程位置。

另外,你似乎在“-scriptBlock”之后缺少括号?

Here is some more information on the issue.here, from MSDN.

+0

我忘了粘贴括号。我的问题是,如果我做gpupdate而不是访问脚本块中的网络路径。它工作正常,如果它是双跳问题,它不应该正常工作? – user3130604 2014-10-17 05:06:13

+0

@ user3130604 gpupdate可以代替“\\ 10.28.64.15 \ EXE \ portqry.exe”,因为gpupdate是本地的。它不必再次验证该PC在本地访问文件。如果您将portqry.exe复制到您正在远程访问并在本地访问的PC,它应该可以正常工作。或者您可以使用链接中的信息解决双跳问题。 – Mokilok 2014-10-18 02:22:23

0

问题是通过刚好在调用命令行中添加-authentication credssp像下面

Invoke-Command -ComputerName $serv -Credential $creds -authentication credssp -ScriptBlock {...}