Skip to content

Instantly share code, notes, and snippets.

@Colby-PDQ
Last active May 6, 2021 13:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Colby-PDQ/ed03a2193e0f02b692b377c90e5d8fda to your computer and use it in GitHub Desktop.
Save Colby-PDQ/ed03a2193e0f02b692b377c90e5d8fda to your computer and use it in GitHub Desktop.
2019-09-19 Webcast Bonus Content
# Written by Jordan Hammond
###Define Variables
$autopath = "C:\Users\Public\Documents\Admin Arsenal\PDQ Deploy\Repository"
$autopackages = @()
$DBPath = "C:\programdata\Admin Arsenal\PDQ Deploy\Database.db"
###Build Package Objects
$test = New-Object psobject -Property @{
Path = "\test"
ScheduleID = "12"
CustomVariable = "MyVer"
}
$obs = New-Object psobject -Property @{
Path = "\OBS Studio"
ScheduleID = "15"
CustomVariable = "OBSVer"
}
###Populate Array
$autopackages += $test, $obs
###To core of That Thing We Are Doing
Foreach($Package in $autopackages){
###Check to see if there is a new Package to Update
If((Get-ChildItem -Directory -Path ($autopath + $Package.path)).count -eq "3"){
###Move The old crap to the Audit Folder and Update the Variable in Inventory and Deploy
$archive = Get-ChildItem -Directory -Path ($autopath + $Package.path) | Where{$_.name -eq "archive"} | select fullname
Get-ChildItem -Directory -Path ($autopath + $Package.path) | Where{$_.name -ne "archive"} | sort creationtime | select -First 1 | Move-Item -Destination $archive.FullName
$NewerVersion = Get-ChildItem -Directory -Path ($autopath + $Package.path) | Where{$_.name -ne "archive"}
& pdqdeploy updatecustomvariable -name $Package.CustomVariable -value $NewerVersion.Name
& pdqinventory updatecustomvariable -name $Package.CustomVariable -value $NewerVersion.Name
###Delete Schedule History
$SQLQuery = "Select Name FROM ScheduleComputers WHERE ScheduleId LIKE $($Package.ScheduleID)"
$ScheduleHistory = $SQLQuery | sqlite3.exe $DBPath
foreach($machine in $ScheduleHistory){
& pdqdeploy DeleteScheduleHistory -Computer $machine -Schedule $Package.ScheduleID
}
}
}
@jclambert
Copy link

Interesting... I'll have to play with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment