© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
O. HeaumeUnderstanding Microsoft Intunehttps://doi.org/10.1007/978-1-4842-8850-4_6

6. Installing the Application

Owen Heaume1  
(1)
West Sussex, UK
 

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.

Only include the msiexec.exe installer program here, you do not specify the actual MSI file that you are going to install.
Start-Process -Filepath "$ENV:SystemRootSystem32msiexec.exe"

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.

You are then able to reference the setup.exe using the shorthand of . (remember, . (a period by itself) means the current directory).
Start-Process -Filepath ".Setup.exe"
Alternatively, you can reference the working directory path using the automatic variable $PSScriptRoot which holds the path that the script is being executed from:
Start-Process -Filepath "$PSScriptRootSetup.exe"
Whether you use . or $PSScriptRoot to reference the root path, remember to include any subdirectories in it if you are storing the setup.exe elsewhere:
Start-Process -Filepath "$PSScriptRootEXE7z1900-x64.exe"
Note

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.

Finally, encapsulate the whole thing in quotes:
-ArgumentList "/I .myMSI.msi /qn /norestart"

-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!)

Of course, you could always rename the file and remove the spaces but luckily, the solution is rather simple: enclose the path and MSI name in double quotes in the -ArgumentList parameter like so:
-ArgumentList ""$PSScriptRootMimecast for Outlook 7.6.0.26320 (32 bit).msi""

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

Listing 6-1 demonstrates a silent installation of the 64-bit version of 7-Zip using the MSI installer.
Start-Process -Filepath "$ENV:SystemRootSystem32↩
msiexec.exe" -ArgumentList "/i $PSScriptRoot7z1900-x64.msi /qn /norestart"
Listing 6-1

A silent installation of an MSI

Example 2 – MSI with Properties

Listing 6-2 demonstrates a silent install of Java using the MSI installer as well as setting several MSI properties.
Start-Process -FilePath "$ENV:SystemRootSystem32↩
msiexec.exe" -ArgumentList"/i $PSScriptRoot↩
jre1.8.0_191.msi /qn JAVAUPDATE=0 AUTOUPDATECHECK=0 ↩ IEXPLORER=1 REBOOT=Suppress" -NoNewWindow -Wait
Listing 6-2

A silent installation of an MSI including the setting of additional properties

Example 3 – Setup.Exe

Listing 6-3 demonstrates silently installing the 64-bit version of 7-Zip using the executable installer and passing the argument for a silent installation.
start-process -FilePath ".7z1900-x64.exe" -ArgumentList ↩
"/S" -NoNewWindow -Wait
Listing 6-3

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset