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.
note* We will be using PowerShell for this.
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). We want the -ErrorAction SilentlyContinue in there 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.
Step 2. Now let's create the trigger that will make this a condition for our package to stop. It is just making sure this step will stop the Deployment on error using the PDQ Deploy Error Mode Option "Stop Deployment with Error". Because the exit code will be 123 and not 0 it will fail and having the Error Mode set to "Stop Deployment with Error" this will halt the package because this process is running.
Step 3. But what if we want to reverse this and stop the deployment if there are no processes running that match that name. It is just swapping the success codes on the Details tab and removing the zero and adding 123.
Comments
0 comments
Article is closed for comments.