Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.


Package step dynamic based on powershell exit code

Step 1. I want to use a powershell step to check to see if a program is open. I would use an exit code of 1 if the program is currently open or an exit code of 0 if the program is not open.

If exit code of 1 do: Step 2. If the program is open I want to display a message informing the user that the program will be updated in 5 mins. Then continue to step 3. If exit code of 0 do: Step 2. If the program wasn't open continue to step 3.

Step 3. Uninstall program Step 4. Install program.

Thanks, Mike



Date Votes
  • Basically I wanted to only display a message if the user had the program open and only continue if the user closed the program or after a timeout. After the program was closed I wanted to uninstall the program then install the new version of the program. This is what I came up with. I created a powershell step and put in the code listed below. You will need to run this step as the logged in user. If the user is logged in and has the program open it will still give the message box and when it times out it will kill the program and continue. I also set the Exit code to 0 so we know that the script has finished successfully and PDQ should continue to the next step in the package.

    This is should be set as the process name when the program is open. get-process -name "x"

    $ProgramProcessName = 'Project Databases'

    Setting values to null

    $Result = $null

    #checking to see if the user has the program open
    $Process = Get-Process -Name $ProgramProcessName -ErrorAction SilentlyContinue

    Doing something based on if the program is open or not

    if($Process -eq $null){ Write-Output "Process is not running" Exit 0 }
    Else{ $date = (Get-Date).ToString() $MessageboxTitle = “Message from $((Get-Date).ToString())” $Messageboxbody = “The $($ProgramProcessName) program will be updated in 3 minutes please save all work and exit out of the program then click ok to continue” $popup = new-object -comobject #Displaying window and saving what the user clicked. The 180=3 minutes and the 0 will just show the OK button. $Result = $popup.popup($Messageboxbody,180,$MessageboxTitle,0) if ($Result -eq 1){ # 1 means the user clicked OK or closed the window # Making sure user closed the program Stop-Process -Name $ProgramProcessName -Force -Confirm:$false -ErrorAction SilentlyContinue Exit 0 } if ($Result -eq -1){ # -1 means the user didn't click OK or the popup hit it's timeout value # Making sure user closed the program Stop-Process -Name $ProgramProcessName -Force -Confirm:$false -ErrorAction SilentlyContinue Exit 0 } }

  • I am using Step 1 before any deployment easy check e.g. Chrome in this case (options - quit deployment with error) :

    $Processes = Get-Process
    if ( $Processes.ProcessName -contains "chrome" ) {
        Write-Output "Process Found - stopping"
        Exit 1
    } Else {
        Write-Output "Process Not Found"
    Exit 0

    Depends of your strategy you can in your message step ask user to close needed program also after 5 min etc and / or just in case add before install step small kill process command in your deployment like:

    Get-Process | Where-Object { $_.Name -contains "chrome" } | Stop-Process -Force -Verbose