0

i recently started to learn powershell and this is kinda my first project. I am trying to automated remote installation. I try to look for solution everywhere, but i cant find the right one. Here is the problem:

I need to instal multiple applications that have multiple version on remote computers.

I try few things but nothing worked so far :(

This one worked for me, but only if i don't use variables. If i use them PS (or i guess cscript.exe) does not recognize them.

$hostname = "yourPc"

$app= "app_0001"

$ver = "v1.0.0"

Invoke-Command -ComputerName $hostname -ScriptBlock {cscript.exe \\$hostname\directory\install.vbs /p:$app /v:$ver}

So i basically end up with \\$hostname\directory\install.vbs /p:$app /v:$ver does not exist. Is it possible to this with cscript.exe?

Thanks.

mklement0
  • 382,024
  • 64
  • 607
  • 775
Tomas91
  • 3
  • 1
  • 1
    install.vbs exist sur every PC? Else put your script into a public share and use public share path for run your command – Esperento57 Nov 18 '20 at 19:28

1 Answers1

0

The code in the script block win run on the remote computer, so it won't have access to your local variables.

You can either add the using: scope modifier to the variables that you want PowerShell to copy to the remote computer:

Invoke-Command -ComputerName $hostname -ScriptBlock {
  cscript.exe \\$using:hostname\directory\install.vbs /p:$using:app /v:$using:ver
}

... or you can explicitly pass values as parameter arguments to the remote scriptblock via the -ArgumentList parameter:

Invoke-Command -ComputerName $hostname -ScriptBlock {
  param($Path,$Application,$Version)

  cscript.exe \\$Path\directory\install.vbs /p:$Application /v:$Version
} -ArgumentList $hostname,$app,$ver
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206