Powershell script Argumentlist not working correctly - powershell

I am trying to install a rather oldish application. I am wanting to do it in powershell because I have post install functions that need to be done in powershell
The -argumentlist is not starting all the arguments after the /qn ( silent mode install )
The application starts and proceeds to install unattended in silent mode but ignores all the arguments after /qn. So its installing without any of the parameters I have specified. Is there anything I am doing wrong? Could just be my quotes are in the wrong places. My powershell knowledge is very very rusty
$workingDirectory = (split-path $myinvocation.mycommand.path -parent)
#Installs my application
Start-Process -Filepath "$workingDirectory\application.exe" -ArgumentList "/args /qn reboot=reallysuppress SILENT=yes INSTALLSTANDALONE=0 CENTRALSERVERHOSTNAME=servername CENTRALSERVERPORT=1234 CSUSER=userName /L*V C:\Windows\Temp\install.log"

I'm assuming you ran the .EXE directly with those args to verify their correctness?
If that's the case, try this:
Start-Process -Filepath "$workingDirectory\application.exe" -ArgumentList "/args", "/qn", "reboot=reallysuppress", "SILENT=yes", "INSTALLSTANDALONE=0", "CENTRALSERVERHOSTNAME=servername", "CENTRALSERVERPORT=1234", "CSUSER=userName", "/L*V", "C:\Windows\Temp\install.log"
Or this:
Start-Process -Filepath "$workingDirectory\application.exe" -ArgumentList #("/args", "/qn", "reboot=reallysuppress", "SILENT=yes", "INSTALLSTANDALONE=0", "CENTRALSERVERHOSTNAME=servername", "CENTRALSERVERPORT=1234", "CSUSER=userName", "/L*V", "C:\Windows\Temp\install.log")
Or this:
& "$workingDirectory\application.exe" /args /qn reboot=reallysuppress SILENT=yes INSTALLSTANDALONE=0 CENTRALSERVERHOSTNAME=servername CENTRALSERVERPORT=1234 CSUSER=userName /L*V C:\Windows\Temp\install.log
Alternatively, what happens when you remove the /qn arg?

I ran into a similar issue.
Changed this:
& "$workingDirectory\application.exe" /args /qn reboot=reallysuppress SILENT=yes INSTALLSTANDALONE=0 CENTRALSERVERHOSTNAME=servername CENTRALSERVERPORT=1234 CSUSER=userName /L*V C:\Windows\Temp\install.log
To this:
& "$workingDirectory\application.exe" /qn reboot=reallysuppress SILENT=yes INSTALLSTANDALONE=0 CENTRALSERVERHOSTNAME=servername CENTRALSERVERPORT=1234 CSUSER=userName /L*V C:\Windows\Temp\install.log
Source: https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx

Related

How to add special characters in MSI installation argument?

Here i trying to install MSI package with argument in powershell where i have to pass few special characters as below:
$msi="/I mypkg.msi TARGETAPPPOOL='.NET v4.5 Classic' /L mai.log /qn"
Start-process "msiexec.exe" -ArgumentList $msi -wait -nonewwindow -PassThru
Showing "1639" error code - A command line option passed to the installer is invalid.
Installation working well with default value, if I remove "TARGETAPPPOOL='.NET v4.5 Classic'”
Can you please suggest how we can write it?
Thanks
Pass the arguments as an array like this:
$msi = '/I', 'mypkg.msi', 'TARGETAPPPOOL=".NET v4.5 Classic"', '/L', 'mai.log', '/qn'
Start-process "msiexec.exe" -ArgumentList $msi -wait -nonewwindow -PassThru
PowerShell automatically adds space separator between the arguments.

Specifying complete installation option when running msi from powershell

I am trying to automate the installation of gstreamer on windows using powershell
I have the msi file downloaded, and am installing it as shown below
PS C:\Users\Administrator> $path = "C:\Users\Administrator\Downloads\gstreamer-1.0-devel-mingw-x86_64-1.18.0.msi";
PS C:\Users\Administrator> Start-Process -Wait -FilePath $path -Argument "/qn"
However, this does not get me the complete installation, because it is only selecting the default arguments from the installer.
I need to specify for it to perform the complete installation, how can I modify my arguments? So that it selects "complete" installation and not "typical" like it does by default
These should work:
Start-Process -Wait -FilePath $path -Argument "/qn","Complete=1"
Start-Process -Wait -FilePath $path -Argument "/qn Complete=1"
I had the same problem, so I ran the Installer from power shell with and without the /qn argument and logged the process into two different files. Finally, I compared the result and I was able to find that for installing process using the UI it adds a property called INSTALLLEVEL, which is set to 1000 (don't know why this value yet). So, by adding the argument INSTALLLEVEL=1000 it installs the complete version.
Start-Process -Wait -FilePath gstreamer-1.0-mingw-x86_64-1.20.2.msi -Argument "/qn INSTALLLEVEL=1000"
I had tried below but it did not work
Start-Process -Wait -FilePath $path -Argument "/qn","Complete=1"
Start-Process -Wait -FilePath $path -Argument "/qn Complete=1"
While this is working fine for me.
Start-Process -Wait -FilePath gstreamer-1.0-mingw-x86_64-1.20.2.msi -Argument "/qn INSTALLLEVEL=1000"

Power Shell Invoking an MSI

I am trying to run an msi installer file using powershell. Below is my power shell code:-
$argumentlist = "/i D:\FolderTest\InstallerTest 1.9.0.39621 Setup.msi /qn /l*v D:\FolderTest\InstallLog.log"
Start-Process -FilePath "C:\Windows\System32\msiexec.exe" -ArgumentList $argumentlist
Every time I try to run this code though The Windows installer appears telling me that the argumentList variable isnt set correctly. Can anybody tell me what the problem is with this code?
I think that spaces in the msi filename are what's preventing the msiexec to work properly. Try something like:
$argumentlist = "/i 'D:\FolderTest\InstallerTest 1.9.0.39621 Setup.msi' /qn /l*v D:\FolderTest\InstallLog.log"
PowerShell is a shell. It's designed to run commands you type. You don't need to use Start-Process. Just type the command and press Enter.
PS C:\> msiexec /i "D:\FolderTest\InstallerTest 1.9.0.39621 Setup.msi" /qn /l*v "D:\FolderTest\InstallLog.log"
As with any command, if a parameter contains spaces, enclose it in quotes.

argument list command not correct

I used the below that works for wusa.exe but it is not working for pkgMGr.exe - I get an error of "The pkgmgr.exe command is incorrect"
I think it is because of the
WORKS:
Start-Process c:\windows\system32\wusa.exe -ArgumentList "$ItalianHyphenationHotfix /quiet /norestart /log" -Wait
NOT WORKING:
Start-Process c:\windows\system32\pkgmgr.exe -ArgumentList "/ip /m: $ItalianKB2841134Hotfix /quiet /norestart /l:C:\buildlog\complogs\LangPack" -Wait
Any ideas how I can fix this? I tried to put the /ip /m before the -Argument list but that did not work as well. I think it is because of these two commands that is causing the issue.
-ArgumentList should be a string array, so you need to format your parameters as such. Try:
Start-Process c:\windows\system32\pkgmgr.exe -ArgumentList "/ip", "/m:`"$ItalianKB2841134Hotfix`"", "/quiet", "/norestart", "/l:`"C:\buildlog\complogs\LangPack`"" -Wait

Retrieving MSIEXEC exit code in PowerShell

I need to run an MSIEXEC command line from a PowerShell and check whether the installation was successful or not.
If I do:
msiexec.exe /qn /l*v e:/tmp/surfaceruntime.log /i '\\nas\lui\tools\surfaceruntime2.msi'
(where the specified MSI doesn't exist – that's for testing purposes)
I get a $LASTEXITCODE of 1
OTOH, if I do:
$parms=#("/qn", "/l*v", "e:/tmp/surfaceruntime.log";"/i";"\\nas\lui\tools\surfaceruntime2.msi")
$run=[System.Diagnostics.Process]::Start("msiexec",$parms)
$run.WaitForExit()
$run.ExitCode
I get 1619 (same as %ERRORLEVEL% if I run the command line from CMD).
How come $LASTEXITCODE is incorrect?
Try this:
(Start-Process -FilePath msiexec.exe -ArgumentList $parms -Wait -Passthru).ExitCode