Powershell在使用UNC路径t的远程计算机上运行exe

时间:2018-11-16 21:33:08

标签: powershell exe

在PC A上,我正在尝试运行此脚本。它应该在PC B上运行Exe。它将运行的Exe驻留在PC C上。这些是Windows 7 OS PC PC C是服务器2008 \ 2012

 $text ='Start-process -FilePath "\\<serverpath>\App.exe" "`-f switch`.switch"'
 Invoke-Command -ComputerName $PCname -Scriptblock { param ($text)
 $text | Invoke-Expression
 } 

$ text中的命令可以从远程PC上的powershell控制台正确运行。 运行整个脚本可以得到: 由于错误,该命令无法执行:访问被拒绝。

做一些研究,我相信我会遇到“ double hop issue”的问题

简要说明。

您有计算机A,B和C。您要从A运行脚本,而B则要在C上运行脚本\进程。您的凭据不会从B传递到C。

由于要求,我认为使用

$cred = Get-Credential Contoso\Administrator
Invoke-Command -ComputerName ServerB -Credential $cred -ScriptBlock {
    hostname
    Invoke-Command -ComputerName ServerC -Credential $Using:cred -ScriptBlock {hostname}
}

如链接中所述。我想遇到的一个问题是,我希望进程在PC B上运行,而该进程仅驻留在PC C上。

1 个答案:

答案 0 :(得分:0)

从PC-A到PB-B和PC-B的远程呼叫需要在PC-C上运行.exe。

Invoke-Command要求您是要尝试击中的目标的管理员,并且仅适用于该目标。

您是说您尝试了最后一块代码,但失败了吗?

因为,如果所有远程处理均已正确配置,则应该以这种方式工作。

$PC_A = 'ws01'
$PC_B = 'iis01'
$cred = Get-Credential "$env:USERDOMAIN\$env:USERNAME"

"Running from $env:COMPUTERNAME"
"Targetng $PC_A"
Invoke-Command -ComputerName $PC_A -Credential $cred -ScriptBlock {
    "Targeting $Using:PC_B from $Using:PC_A via remote source"
    Invoke-Command -ComputerName $Using:PC_B -Credential $Using:cred -ScriptBlock {"PC_B name is $env:COMPUTERNAME"
        notepad.exe
        Get-Process -Name notepad
    }
}

# Results

Running from DC01
Targetng ws01
Targeting iis01 from ws01 via remote source
PC_B name is IIS01

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName  PSComputerName
-------  ------    -----      ----- -----   ------     -- -----------  --------------
    172      10     2184       9424 ...29     0.02   3520 notepad      ws01

您还应该考虑在第二跳上将PSDrive用于.exe,而不是额外的远程工作,并像在第一跳上一样运行.exe。

相关问题