Argument list to start-process?

Hi all,

This is my very first post and I’m trying to teach myself Powershell. I could greatly use your help with something. There are lots of computers I need to install an .exe on but I wanna do it through Powershell if I can. One of the steps involved were I to install manually is click ‘Browse’ and point to a directory location different than the one given by default, and I know not how to specify that in Powershell. This is my command. Can I pass this path as an argument to start-process command?

invoke-command -computername $computer -scriptblock {Start-Process -FilePath $sourcefile}

Thanks for any help you can provide. I appreciate it.

Welcome to PowerShell.org forums.

Definitely you can. You can use the param block inside scriptblock and use -ArgumentList parameter of Invoke-Command.

Invoke-Command -computername $computer -scriptblock {
    Param($FilePath)
    Start-Process -FilePath $FilePath
} -ArgumentList <Path here>

Thank you, but it looks like you omitted $sourcefile, which is the actual file to be executed. Where does it fit in the above block?

Also, does the path need to be in quotes (i.e. “c:\test”)

Here are the examples:

$sourceFile = "C:\my path\my.exe"

Invoke-Command -computername $computer -scriptblock {
    Param($FilePath)
    Start-Process -FilePath $FilePath
} -ArgumentList $sourceFile

Or…

$sourceFile = "C:\my path\my.exe"

Invoke-Command -computername $computer -scriptblock {
    Start-Process -FilePath $using:sourceFile
} 

Keep in mind that path and exe will need to exist on the remote systems.

Thanks so much. Just to be clear, I am dealing with two paths. The .exe to be installed is on a network location, and the argument to be passed is a local path (i.e. c:\test).

Hi all,

How would I do this if I wanted to install on my local machine? The .exe is on my local C drive. I suppose I would rid of ‘invoke-command’ altogether, but I don’t know how to pass the directory path with just start-process.

start-process -FilePath $sourcefile

Something like this, but I need to pass in the argument. Thanks.

Get-Help Start-Process -Parameter ArgumentList

-ArgumentList <String[]>
    Specifies parameters or parameter values to use when this cmdlet starts the process.
    
    Required?                    false
    Position?                    1
    Default value                None
    Accept pipeline input?       False
    Accept wildcard characters?  false

When using a cmdlet, its always good to check the examples provided in the help.
Get-Help Start-Process -Examples
Start-Process (Microsoft.PowerShell.Management) - PowerShell | Microsoft Docs

-ArgumentList parameter takes collection of arguments for the executable. If there is an exe named someexe.exe which takes -p and -s, then

Start-Process -FilePath c:\temp\someexe.exe -ArgumentList '-p','-s'

another example

Start-Process net.exe -ArgumentList 'user Administrator'

#or

Start-Process net.exe -ArgumentList 'user'