Last active
May 6, 2021 13:50
-
-
Save Colby-PDQ/ed03a2193e0f02b692b377c90e5d8fda to your computer and use it in GitHub Desktop.
2019-09-19 Webcast Bonus Content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting... I'll have to play with this.