Start-Process系统找不到指定的文件

时间:2018-03-02 17:13:25

标签: powershell-v3.0

需要一些帮助才能找到下面的问题。

问题在于$ setup

Start-Process -workingdirectory c:\ temp $ setup -wait

        $storageDir = 'C:\Temp'
        $file = '1.1.1.1'
        $SpecIP = '192.168.0.87'
        $password = ConvertTo-SecureString "Password" -AsPlainText -Force
        $user = "User1"
        $cred = New-Object System.Management.Automation.PSCredential    ($user,$password)
  $rsName =  'Responses.txt'
        $setup = "$file.exe $rsName"

以下作品我对值进行硬编码

Invoke-Command -ComputerName $SpecIP -Credential $cred -ScriptBlock {
param($setup)
Start-Process -workingdirectory c:\temp 1.1.1.1 Responses.txt -wait
} -ArgumentList $setup

唯一不同的是$ setup

Invoke-Command -ComputerName $SpecIP -Credential $cred -ScriptBlock {
param($setup)
Start-Process -workingdirectory c:\temp $setup -wait
} -ArgumentList $setup

错误

  

由于错误,无法运行此命令:系统找不到指定的文件。       + CategoryInfo:InvalidOperation :( :) [Start-Process],InvalidOperationException       + FullyQualifiedErrorId:InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCo      mmand       + PSComputerName:192.168.0.87

1 个答案:

答案 0 :(得分:3)

我发现了这个问题。我需要在exe名称之前添加.\

$setup = ".\$dirchosen.exe $rsName"

Start-Process powershell -workingdirectory c:\temp "$setup" -wait
相关问题