Add a Process condition to a Deploy Package

Purpose

You wish to use a running process condition in a PDQ Deploy Package to either stop deployment if that process is running or stop deployment if that process is not running.

 

Resolution:

1. Create a PowerShell step to determine if our process is running and throw an exit code if it is.

2. Create a package to use this exit code to stop a deployment package if this process is running.

3. Create a package to use this exit code to stop a deployment package if this process is not running.

 

Step 1. Create the script

We will use the same PowerShell script for both options.

# Specify multiple process names by separating them with commas
$Processes = @("Chrome")

if (Get-Process -Name $Processes -ErrorAction SilentlyContinue){

Exit 123
}

In the script above, the Exit code will be 123 if the process that the $Processes variable represents is running, and 0 if there are no processes matching that variable (be sure this name matches exactly or use proper wildcards). Be sure to include -ErrorAction SilentlyContinue so the script will not produce any other results than what we want which is an exit code of 0 or 123.  If you need to know how the name is reported in the running processes list, you can get that list by running a command to list the processes and filter by name. 

Get-Process | Select Name

This is what the Step will look like below.

processRunning.png

 

Step 2. Create the trigger to stop the deployment if the process is running

Now let's create the trigger that will make this a condition for our package to stop. This will ensure that this step will stop the Deployment on error by using the PDQ Deploy Error Mode Option, "Stop Deployment with Error". Since the exit code will be 123 and not 0, it will fail and having the Error Mode set to "Stop Deployment with Error" will halt the deployment.

Stop.png

 

Step 3. Create the trigger to stop the deployment if the process is not running

If you want to reverse this and stop the deployment if there are no processes running that match that name, swapping the success codes on the Details tab by removing the zero and adding 123 should accomplish that.

Stop2.png

Still have a question or want to share what you have learned? Visit our Community to get help and collaborate with others.