Installing the application is going to be the primary purpose of the deployment script and in Chapter 2 you learned that msiexec.exe was the tool to use. However, you cannot just enter msiexec.exe and the command line straight into your PowerShell script and expect it to work, it needs to be called from a PowerShell cmdlet first.
In this chapter, you will learn how to install either an MSI or setup.exe using PowerShell and the associated common cmdlet parameters.
Start Your Engines Please
Well, the subtitle is a bit misleading here because you’re not starting an “engine” per se, more a process, using the native PowerShell cmdlet: Start-Process.
You will be pleased to know that if you need to install either an MSI or a setup.exe, the same cmdlet is used.
The Start-Process cmdlet will do exactly as its name suggests, and reading the help file for it shows that it is very flexible in what it can do; not just launching programs (such as msiexec.exe) directly, but also, by specifying a nonexecutable file the cmdlet will start the program associated with the file.
Parameters
The cmdlet Start-Process has a lot of parameters; however, you tend to use only four. Let’s look at these in a bit more depth to see how and why you would use them.
-FilePath
This parameter must be supplied with a path to an executable, and depending on which one you are going to install (MSI or EXE) the -filepath parameter will be different.
MSIEXEC
This is where you will specify the path to msiexec.exe and you should remember to use the PowerShell built-in environment variables wherever you can.
EXE
If you are deploying a setup.exe, then you must specify the path and name of the executable.
As explained in Chapter 5, your deployment script should contain the code Set-Location $PSScriptRoot to set the current working directory to that which the script is being executed from.
Although I have demonstrated including the path to msiexec.exe or the setup.exe in the -Path parameter, you could also use the -WorkingDirectory parameter for this instead, and then only specify the EXE name in the path parameter. I tend not to use this parameter, but for clarity, you may prefer to in your scripts. The syntax for msiexec.exe would then be as follows: Start-Process -FilePath "msiexec" -WorkingDirectory "$ENV:SystemRootSystem32" and for a setup.exe you would use Start-Process -FilePath "Setup.exe" -WorkingDirectory "$PSScriptRoot".
-ArgumentList
This parameter is where you will add the program arguments.
Minimum Information
For a setup.exe, as a minimum, you will want to add the argument to signify a silent installation should occur.
For an MSI you will need to signify that an installation should take place by using the /i parameter (or /x should you wish to uninstall), followed by the path to, and name of the MSI installation file and then the silent install switch.
You may have additional parameters or properties to set, depending on what you are trying to achieve, and they may be added here too, after the MSI name.
-NoNewWindow
This parameter starts the new process in the current console window. By default, PowerShell opens a new window, and you don’t want that.
-Wait
This parameter suppresses the command prompt and retains the window until the process has finished. In other words, “Don’t do anything else until the application has finished installing.”
Don’t miss this parameter out or your script may go a bit screwy if you are adding post-deployment tasks that are dependent on the MSI or setup.exe installation to complete first.
Dealing with Spaces
What if you have spaces in the MSI file name? For example, if the MSI was named: Mimecast for Outlook 7.6.0.26320 (32 bit).msi (True story!)
Putting It All Together
Now that you have learned about the individual parameters required for a successful installation to occur using Start-Process, it’s time to put it all together with some examples.
Example 1 – Simple MSI
A silent installation of an MSI
Example 2 – MSI with Properties
A silent installation of an MSI including the setting of additional properties
Example 3 – Setup.Exe
A silent installation of a setup.exe
Summary
Compared to the five previous chapters, this was a short one. You learned how to use PowerShell to deploy either an MSI or a setup.exe, the parameters you should use, and why you use them. You also learned what to do if the command line included spaces, and finally were shown three examples of how to call your installation using the Start-Process cmdlet.
In the next chapter, you will learn about deploying a PowerShell script or template and the subtle nuances of each script type.