Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Aborts all Running, Connecting, and Queued deployments.
# Written by Colby Bouma
# Aborts all runnings deployments. Based off of this script:
# v 003
$Deploy_DB_File = "$env:SYSTEMDRIVE\ProgramData\Admin Arsenal\PDQ Deploy\Database.db"
$Error_Message = "<Error><Message>Aborted</Message><Type>AdminArsenal.Remote.Agent.AbortedException</Type><StackTrace></StackTrace></Error>"
# This is a stripped down version of a function from a blog post I am writing
function Submit-Query ( $Query ) {
$Query_Output = sqlite3.exe "$Deploy_DB_File" "$Query" 2>&1
# I borrowed the error handling from this, but kind of went my own way with it
if ( $Query_Output.Exception -ne $null ) {
Write-Log "ERROR: Submit-Query encountered an error"
Write-Log $Query_Output.Exception
} else {
return $Query_Output
function Write-Log {
$Timestamp = Get-Date -Format "HH:mm:ss.fff"
$Log_Message = "$Timestamp --- $args"
Write-Output $Log_Message
$DeploymentComputerIds_To_Abort = Submit-Query "SELECT DeploymentComputerId FROM DeploymentComputers WHERE NOT Stage = 'Finished';"
ForEach ( $DeploymentComputerId_To_Abort in $DeploymentComputerIds_To_Abort ) {
$Stage = Submit-Query "SELECT Stage FROM DeploymentComputers WHERE DeploymentComputerId = $DeploymentComputerId_To_Abort;"
if ( $Stage -eq "Queued" ) {
# Unfortunately the DeploymentUser isn't populated for Queued deployments, so we have to retrieve it from the Credentials table.
$DeploymentId = Submit-Query "SELECT DeploymentId FROM DeploymentComputers WHERE DeploymentComputerId = '$DeploymentComputerId_To_Abort';"
$UserId = Submit-Query "SELECT UserId from Deployments WHERE DeploymentId = '$DeploymentId';"
$DeploymentUser = Submit-Query "SELECT UserName FROM Credentials WHERE CredentialsId = '$UserId';"
} elseif ( $Stage -eq "Running" -or $Stage -eq "Connecting") {
$DeploymentUser = Submit-Query "SELECT DeploymentUser FROM DeploymentComputers WHERE DeploymentComputerId = $DeploymentComputerId_To_Abort;"
} else {
Write-Log "ERROR: Colby didn't account for Stage: $Stage"
$Ended = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
if ( $DeploymentUser -ne $null ) {
Submit-Query "UPDATE DeploymentComputers SET
Stage = 'Finished', Error = '$Error_Message', DeploymentUser = '$DeploymentUser', Ended = '$Ended'
WHERE DeploymentComputerId = '$DeploymentComputerId_To_Abort';"

This comment has been minimized.

Copy link
Owner Author

Colby-PDQ commented Nov 22, 2017

003 fixes an issue where the Run Time would increase forever because I didn't fill in the Ended field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.