I have a PowerShell script for installing software on remote computers.
To date I have been successfully using the following code:
$prog = "ping"
$arg = "localhost"
$computername = "MACHINE01"
invoke-command -computername $computername {param($p,$a)& $p $a} -ArgumentList $prog,$arg
I now need to install an MSI, Eg. 'msiexec /i c:\file.msi /passive'.
I cannot get MSIEXEC to treat everything after 'MSIEXEC' as parameters. Instead, PowerShell just tries to execute it as one big command. I have had tried numerous things mostly involving the placement of literal quotes but cannot get this to work.
I have now abandoned the call operator (&) in favour of 'Start-Process' which has an '-ArgumentList' parameter. The MSI now executes correctly. Great!
invoke-command -computername $computername {param($p,$a) start-process $p -argumentlist $a -nonewwindow -wait -redirectstandardoutput c:\output.txt; get-content c:\output.txt} -ArgumentList $prog,$arg
The problem with 'Start-Process' is that it does not produce any console output when run remotely using 'Invoke-Command'. I have had to resort to redirecting the output to a file and then reading the file. Is there a better way?