Remote instal vbs in Powershell.

Hello guys, i recently started to learn powershell and this is kinda my first project. I am trying to automated remote instalation. 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 :frowning:

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

 

$hostname = “yourPc”
$app = “app_0001”
$ver = “1.0.0”
Invoke-Command -ComputerName $hostname -ScriptBlock {cscript.exe \$hostname\directory\install.vbs /p:$app /v:$ver}

Remove-PSSession $s

 

So i basicly end up with \$hostname\directory\install.vbs /p:$app /v:$ver does not exist. Is it possible to do this with cscript.exe? Can u help me with solution?

 

Thanks for your time and answers.

Local variables are not accessible inside the invoke-command script block. You must either pass them in as arguments or preface with $using. i.e. $using.hostname.

Get-Help about_remote_variables

[quote quote=272671]Local variables are not accessible inside the invoke-command script block. You must either pass them in as arguments or preface with $using. i.e. $using.hostname.

Get-Help about_remote_variables

[/quote]

Thank you! It works perfectly :slight_smile:

Also, the VBScript can and should be converted to Powershell (or something not VBScript). VBScript is being deprecated. From first glance of the params, you should look at Get-ChildItem and Start-Process. Not sure if those params are building a path and how it knows what to execute in the directory. Re-writing the vbScript wrapper would be a good next project. :slight_smile:

[quote quote=272977]Also, the VBScript can and should be converted to Powershell (or something not VBScript). VBScript is being deprecated. From first glance of the params, you should look at Get-ChildItem and Start-Process. Not sure if those params are building a path and how it knows what to execute in the directory. Re-writing the vbScript wrapper would be a good next project. 🙂

[/quote]

Thanks for tip. After i finish this one i might look at it. But after first look just from the lenght/structure of the scripts it will take me some time to get this level of knowledge :slight_smile: I am currenty at IT Service Desk position and all those scripts always make our Desktop support or sys admins.

I got one more question. Now i finished my whole script and i have a issue with this way of remote instalation. This part of script i posted works by its self… But… It doesnt work with combination with read-host in it. I need some user input, like that application number and his version, but it always ends, before user can give any input…

I tried to experiment with New-PSSession but its ends the same way… I could completely overwrith the script and use this method that Mike suggest just for the instlation, but there must be a better way… Any other tip please?

 

Where are you putting Read-Host in your script? Anything in the script block of Invoke-Command happens on the remote machine not the one running the command. Can you post your script?

Thanks for your reply. I had it in invoke-command block. I rebuild it outsite it turns out its not that many changes…