hi all,

made a powershell script to install msi/exe’s (havnt done the exe’s yet)

get-childitem -path C:\remoteinstalls\ -filter "*.msi" | select-object -expandproperty name > C:\remoteinstalls\msi.txt
get-childitem -path C:\remoteinstalls\ -filter "*.exe" | select-object -expandproperty name > C:\remoteinstalls\exe.txt
$msi = get-content -path C:\remoteinstalls\msi.txt
$exe = get-content -path C:\remoteinstalls\exe.txt
$Session = New-PSSession -ComputerName (get-content C:\remoteinstalls\hosts.txt)
Copy-Item c:\remoteinstalls -Destination c:\ -ToSession $Session -Recurse -force
foreach ($m in $msi) {
invoke-command -session $Session -ScriptBlock {start-process -filepath msiexec -argumentlist "/i ""C:\remoteinstalls\$using:m"" /norestart /qb!" -passthru -wait}
}

but when i do passthru it doesnt state that the msi has been successfully installed or not, i just get this

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName                                          PSComputerName
-------  ------    -----      -----     ------     --  -- -----------                                          --------------
    134       9     5884       7864       0.00   6240   0 msiexec                                              172.17.1.3
    134       9     5892       7868       0.02   8188   0 msiexec                                              172.17.1.3
    137       9     6004       8516       0.02   3212   0 msiexec                                              172.17.1.3
    134       9     5888       7872       0.00   4664   0 msiexec                                              172.17.1.3
    137       9     6080       8584       0.02   1804   0 msiexec                                              172.17.1.3

i know i could do an if $? after my start process command but what do the above mean please

thanks,

rob

9 Spice ups

In the Invoke Command line, you have a bunch of double quotes. You have to stagger between the double and single quotes or they will cancel each other out. maybe try using this line instead

Invoke-Command -Session $Session -ScriptBlock {Start-Process -FilePath msiexec -ArgumentList "/i C:\remoteinstalls\$using:m /norestart /qb!" -PassThru -Wait}
1 Spice up

the reason why i have put 2 double quotes is to escape it as this document says

if you read argument list it says if it contains spaces you need to escape it with quotes

The outer quotes of the PowerShell strings aren’t included when the ArgumentList values are passed to the new process. If parameters or parameter values contain a space or quotes, they need to be surrounded with escaped double quotes. For more information, see about_Quoting_Rules.

It does look like there are too many double quotes together. If I am not mistaken, isn’t there an escape character so you could still write the double quotes. I believe it is ` or if not that then .

So basically this line would read:

invoke-command -session $Session -ScriptBlock {start-process -filepath msiexec -argumentlist “/i "C:\remoteinstalls\$using:m” /norestart /qb!" -passthru -wait}

or

invoke-command -session $Session -ScriptBlock {start-process -filepath msiexec -argumentlist “/i "C:\remoteinstalls$using:m" /norestart /qb!” -passthru -wait}

1 Spice up

I do similar things regularly and what @Gorfmaster1 has is correct. Unless you plan on doing the -Arg “-i”,”extra-command”. Also, it doesn’t look like you’re setting many of the MSI or EXE files with long names in weird folders like ${env:tmp}\file.msi. That’s a big help to not need the extra quotations.
I think the errors you’re seeing are the CLI errors form MSI saying it can’t find the MSI for the arguments you have and the numbers are the pointers to show how to use them.

Give @Gorfmaster1’s example a try on 1 or 2 machines and see what happens.

i tested @jonathanhackett ​ and the 1st one worked while the 2nd one didnt ie the ` worked while the \ didnt

but so did my " just wondering if you can use this aswell

1 Spice up