从unc路径访问exe

时间:2014-10-17 00:19:16

标签: powershell portqry

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

#获取森林名称

$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 }}

2 个答案:

答案 0 :(得分:0)

您所遇到的问题看起来就像着名的PowerShell双跃点问题。 基本上,当通过Invoke-command进行远程处理时,您无法访问远程位置。

此外,在" -scriptBlock"?

之后,您似乎缺少括号

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

答案 1 :(得分:0)

只需在调用命令行中添加-authentication credssp就可以解决此问题,如下所示

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