Power Shell Invoking an MSI - powershell

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.

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.

Powershell start-process issue when path contains R character after parenthesis

I am trying to install msi from commandline using powershell command. My msi path contains R character after parenthesis. Due to this powershell throws below error.
PowerShell.exe -ExecutionPolicy Bypass Start-Process -Wait -FilePath msiexec -ArgumentList /i, `"c:\program files\xxx (R) xxx.msi`"
If my path contain no parenthesis, it is working fine. Can someone help me resolve this issue.
Do not suggest some other method to do it. I would like to know the path issue as it works when my msi path doesnt have parenthesis.
From PowerShell:
# Note that parameter -FilePath is implied for `msiexec`, and
# -ArgumentList for `'/i ...'`
Start-Process -Wait msiexec '/i "c:\program files\xxx (R) xxx.msi"'
The most robust approach is to use a single -ArgumentList (-Args) argument that encodes all arguments, using embedded quoting, rather than passing arguments individually, due to a long-standing bug detailed in this answer.
From cmd.exe, there's no reason to involve PowerShell in this case; the built-in start command will do:
start /wait msiexec /i "c:\program files\xxx (R) xxx.msi"

Powershell script Argumentlist not working correctly

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

Run powershell in new window

I would like to run new powershell window with parameters. I was trying to run following:
powershell -Command "get-date"
but everything happens in same console. Is there a simple way to do this?
To open a new PowerShell Window from PowerShell:
Start-Process PowerShell
Or my personal favorite:
Start-Process PowerShell -WindowStyle Maximized
Then you could typeGet-Datewithout having to deal with the -ArgumentList's tendency to close itself. I still haven't found a way to open a new PowerShell process with the -ArgumentList Parameter, without it immediately closing after it runs. For Instance:
Start-Process PowerShell -ArgumentList "Get-Date"
or simply
Start-Process PowerShell -ArgumentList Get-Date
Will Close Immediately after running the process.
In order to get it to wait before closing you could add:
Start-Process PowerShell -ArgumentList 'Get-Date; Read-Host "Press Enter"'
Since the -Wait Parameter seems to do nothing at all in this case.
FYI - PowerShell Suggested Syntax is actually:
Start-Process -FilePath "powershell.exe"
But since PowerShell is a standard Windows Application in the %SystemRoot%\system32 Environment Variables the command line(s) should recognize a simple
Powershell
Command
Use the start command. In a CMD prompt, try:
start powershell -noexit -command "get-date"
For Start/Run (or Win+r) prompt, try:
cmd /c start powershell -noexit -command "get-date"
The -noexit will tell Powershell to, well, not to exit. If you omit this parameter, the command will be executed and you are likely to just see a glimpse of a Powershell window. For interactive use, this is a must. For scripts it is not needed.
Edit:
start is an internal command for CMD. In Powershell it is an alias for Start-Process. These are not the same thing.
As for why the window is black, that's because the shortcut for Powershell.exe is configured to set the background blue.
To call a PowerShell (PS) script in a second terminal window without exiting, you can use a script similar to:
Start-Process PowerShell -ArgumentList "-noexit", "get-date"
or if you need to run another script from a specific location:
Start-Process PowerShell -ArgumentList "-noexit", "-command .\local_path\start_server.ps1"

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