Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start-Process The system cannot find the file specified

Need some help to find the problem with the below.

The issue is around the $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"

The following works I hard code the value

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

Not working the only different is the $setup

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

Error

This command cannot be run due to the error: The system cannot find the file specified. + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCo mmand + PSComputerName : 192.168.0.87

like image 435
Matt Avatar asked Mar 02 '18 17:03

Matt


1 Answers

I found the issue. I needed to add a .\ before the exe name.

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

Start-Process powershell -workingdirectory c:\temp "$setup" -wait
like image 53
Matt Avatar answered Nov 20 '22 19:11

Matt