Mike skovby
Mike skovby

Reputation: 53

Start-process: both positional parameter and can't locate file specified

Ok, So I am working on the powershell remote deployment of software to ADUsers. I have remote access to the computer and all, no problems there.

Right now I am at the point where I have a exe file from Ninite to just install 7zip onto the client pc just to see when it works so i can start deploying some bigger programs to it.

The guide I have found to help me deploy out the software for now looks like this:

Invoke-Command -ComputerName *REDACTED* -Scriptblock {
    Start-Process C:\Users\Administrator\Documents\ninite_7_zip\Ninite 7Zip Installer.exe '/silent' -wait
}

When I do run this code, I get the error:

A positional parameter cannot be found that accepts argument 'Installer.exe'.

So I thought to myself, that it might be because of the spaces in the name. So therefore I changed it to:

Invoke-Command -ComputerName *REDACTED* -Scriptblock {
        Start-Process C:\Users\Administrator\Documents\ninite_7_zip\Ninite_7Zip_Installer.exe '/silent' -wait
    }

And ofcourse also changed it's name within the folder to match the "newly made" code.

But the error now changed into:

This command cannot be run due to the error: The system cannot find the file specified

Even though I use Powershell ISE, and I used it's guideboxes when writing, to enter the folder and find it, when I wrote the directory.

My only goal in this, is that I want to remotely run and complete this installer on the client PC when deployed from the DC upon which the file lies.

Anybody got a qualified guess? Or maybe even so, a solution.

Thanks in advance for your kind answers.

Upvotes: 0

Views: 460

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

When I do run this code, I get the error:

A positional parameter cannot be found that accepts argument 'Installer.exe'.

You'll want to use quotation marks to qualify path names with spaces in them:

Start-Process 'C:\Users\Administrator\Documents\ninite_7_zip\Ninite 7Zip Installer.exe' '/silent' -wait

But the error now changed into:

This command cannot be run due to the error: The system cannot find the file specified

Even though I use Powershell ISE, and I used it's guideboxes when writing, to enter the folder and find it, when I wrote the directory.

ISE is not smart enough to realize that the scriptblock is to be executed on a remote computer, so it completes the path based on your local file system.

You still need to copy the executable to the remote machine in order to execute it:

# first copy the installer to remote file system
$remoteSession  = New-PSSession -ComputerName $computerName
$localInstaller = 'C:\Users\Administrator\Documents\ninite_7_zip\Ninite 7Zip Installer.exe'
$remotePath     = Invoke-Command -Session $remoteSession -ScriptBlock { $env:TEMP }
Copy-Item $localInstaller -Destination (Join-Path $remotePath "7zInstaller.exe") -ToSession $remoteSession

# now we can invoke the executable on the remote machine (re-using the same remoting session)
Invoke-Command -Session $remoteSession -ScriptBlock {
  Start-Process (Join-Path $env:TEMP "7zInstaller.exe") '/silent' -Wait
}

# clean up
$remoteSession |Remove-PSSession |Out-Null

Upvotes: 1

Related Questions