Sequential Software Installation

Suppose that one has the following functions:

function InstallPackage1
{
start-process msiexec /i package1.msi /qn
}

function InstallPackage2
{
start-process msiexec /i package2.msi /qn
}

What’s the best way to run these if I want the first package to run first, then have the second package wait for the first to complete before starting? I looked into workflows, but am wondering if there’s another way (e.g., InstallPackage1 -wait InstallPackage2…).

Thanks.

Hi Brandon,

You can ue the -Wait parameter with Start-Process for this to occur.

The only thing you need to watch with this is that the msiexec doesnt launch another process and then quit itself from the installation. It’s less likely with msi files though.

Thanks for the response Tim.

If I have several functions using the wait parameter, for example:

function InstallPackage1
{
start-process msiexec /i package1.msi /qn -wait
}

Would calling each function one after the other yield the desired result?

InstallPackage1
InstallPackage2
etc.

Or would it be necessary to combine them all into one function?:

function InstallPackages
{
start-process msiexec /i package1.msi /qn -wait
start-process msiexec /i package2.msi /qn -wait
}

Thanks again.

Now that I think about it, calling the functions one after the other or combining them into one should yield the exact same results (since calling the function just executes the code inside).

I’ll test the first method, but I’m curious if workflows would be appropriate here (probably not because some commands require user input).

Here is what we use at my company that works very well for different types of installs.

# Function Get_Running_Process
## Get_Running_Process looks for the following running processes:
## ~ wscript
## ~ cscript
## ~ msg
## Each time a process is found to be running the error count goes down.
## The resulting action is to loop through the running processes until all three are no longer running.
## Once wscript and cscript end the script looks for the msg process.  If the msg process is found to be running,
## the process is terminated with force to supress the prompt.  Once all errors are clear, script gets any orphaned
## msiexec processes and terminates them.
function Get_Running_Process() {
	Get-Process wscript -ErrorVariable err -ErrorAction SilentlyContinue
	Get-Process cscript -ErrorVariable +err -ErrorAction SilentlyContinue 
	Get-Process msg -ErrorVariable +err -ErrorAction SilentlyContinue
	do {
		if($err.count -lt 3) {
			Get-Process wscript -ErrorVariable err -ErrorAction SilentlyContinue 
			Get-Process cscript -ErrorVariable +err -ErrorAction SilentlyContinue 
			Get-Process msg -ErrorVariable +err -ErrorAction SilentlyContinue
			Get-Process msg -ErrorVariable msg -ErrorAction SilentlyContinue
			if($msg.count -eq 0) {
				Stop-Process -ProcessName msg -Force
			}
		}
	}
	until($err.count -eq 3)
	$err.Clear()
	Get-Process msiexec -ErrorVariable err -ErrorAction SilentlyContinue
	if($err.Count -eq 0) {
		Stop-Process -processname msiexec -Force
	}
	Start-Sleep -Seconds 5
}

# Redundant but in our environment necessary. 
$err.Clear()
Get-Process msiexec -ErrorVariable err -ErrorAction SilentlyContinue
if($err.Count -eq 0) {
	Stop-Process -processname msiexec -Force
}

cscript "\\server\runinst.vbs" | Out-Null
Get_Running_Process

Start-Process "\\server\install.bat" -Wait | Out-Null
Get_Running_Process

This is the scaled down version. We have about 20 applications that get installed via a form with checkboxes. If the box is checked then the application install with the above parameters.

I know that dealing with MSI’s is difficult so I chose to get this package off of Githhub to install and check my msi status:

https://github.com/heaths/psmsi

I have some sample code that I used to install ARR… AT the time I wrote this i was using Octopus for continous integration. So you may have to change the scripting a bit. Hopefully this helps in some small way.

I’ll post that code on my github gist account here:

https://gist.githubusercontent.com/crshnbrn66/2a45a52712dd8190ac73/raw/810d5e535190b945fcf46825e71478b6a9d6ba88/setup-arr.ps1