Norskyi
Norskyi

Reputation: 151

Install software remotely - hangs

I am trying to deploy a software using Powershell in my domain and for some reason, the script hangs during the "Start-Process" cmdlet.

Here is what I have:

Invoke-Command -ComputerName $servers -Credential $creds -ScriptBlock {
   $args = "/param1=`"{0}`" /param2=`"{1}`" /param3=1 /S" -f "value1", "value2"
   Start-Process "c:\temp\installer.exe" -Wait -ArgumentList $args
}

The interesting part is that I have no issue if I manually Enter-PSSession into a single server and run:

Enter-PSSession one_server
cd c:\temp\
$args = "/param1=value1 /param2=value /param3=1 /S"
Start-Process .\installer.exe -Wait -ArgumentList $args

Any ideas? Thanks

Upvotes: 0

Views: 321

Answers (2)

Norskyi
Norskyi

Reputation: 151

The solution turned out to be permission elevation which required "-Verb RunAs". Special thanks to Mark Arend for making me aware of the reserved $arg variable.

Invoke-Command -ComputerName $servers -Credential $creds -ScriptBlock {
   $args = "/param1=`"{0}`" /param2=`"{1}`" /param3=1 /S" -f "value1", "value2"
   Start-Process "c:\temp\installer.exe" -Wait -ArgumentList $args -Verb RunAs
}

Upvotes: 1

Mark Arend
Mark Arend

Reputation: 164

Change your variable $args to another name, like $a or $arguments. $args is reserved, and is a system.array object. You want to create a string.

Upvotes: 1

Related Questions