Skip to content

How to delete all target history from a schedule

Black and White PDQ logo
Kris Powell|August 3, 2017
Delete all Target History from a Schedule
Delete all Target History from a Schedule

Today, we’re going to show how to delete all target history from a schedule using PowerShell.

If you’re using PDQ products, you’re already ahead of the game. We’ve got packages, and schedules, and collections! (oh my!)

We know how “fun” it is re-imaging and baselining all your computers. Getting everything installed perfectly can be a challenge.

When it comes time to re-image and baseline your computers, however, you’ll probably want to delete any existing target history from your schedules.

So sit back, relax, grab that whiskey and let’s “learn” you something new in PowerShell.

What is target history?

What’s the target history, you ask? I’m so very glad you asked!

The target history is a record of deployments per target, per package, and per schedule.

Target history tab, schedule window

This target history keeps track of which targets have successfully received any package that is attached to a given schedule.

This allows us to selectively deploy packages when used hand-in-hand with another feature in order to prevent schedules from continually redeploying software to targets.

Stop deploying to targets once they succeed is selected in the schedule options, it keeps track of deployments per package and per target.

Packages attached to a schedule will stop deploying after a successful deployment

Read more about this option in our documentation.

Sometimes, however, you may find yourself needing to redeploy some software to the same targets via the same schedule. In order to do this, you have two options:

  • Delete and recreate the schedule (boo!)

  • Delete the target history (hurray!)

One example of when you might want to do this is when you reimage a computer with the same host name. Without deleting the target history for a given schedule, the PDQ Deploy schedule thinks the target has already been deployed to successfully.

Fortunately, you can delete the target history directly from the GUI, or if you’re hip and cool and enjoy automation, then you can also use the PDQ Deploy command line interface (CLI).

But, since the CLI is limited to only removing one target at a time, how would you go about removing all target histories from a schedule?!

Enter PowerShell! (cue superhero theme music)

How to delete all target history from a schedule in 4 steps

With PowerShell, we can find out which computers are part of the schedule’s target history. Then, we can proceed to individually remove each target from the schedule via a loop.

1. Select database

Here, we simply need to identify which database that we want to use. Since we’re working with PDQ Deploy, I’m going to point it to the PDQ Deploy database.

$db = "C:\ProgramData\Admin Arsenal\PDQ Deploy\Database.db"
Schedule-Target-History-3

2. Get Schedule ID

Next, we use SQLite to query the Schedules table to find out the Schedule ID. If you already know the schedule ID, you can skip this step.

$ScheduleName = "Stop exploding you cowards!" $SQL = "SELECT ScheduleID FROM Schedules WHERE Name like '$ScheduleName';" $ScheduleID = sqlite3.exe $db $sql $ScheduleID
Schedule-Target-History-4

3. Get target names with Schedule ID

Using the result from the previous step, we’ll use the Schedule ID to find out which targets currently have a history for the schedule.

# Get target names from ScheduleId $sql = "select Name from ScheduleComputers where Scheduleid = $ScheduleId;" $Computers = sqlite3.exe $db $sql $Computers
Schedule-Target-History-5

4. Loop through list of names and delete history

Now, we can finally loop through each target and remove the target history for our schedule.

# Remove schedule history for each target and scheduleid) foreach ($Target in $Computers) {    pdqdeploy deleteschedulehistory -Computer $Target -Schedule $ScheduleID }
Schedule-Target-History-6

Putting it all together

Now that we’ve covered each section, let’s throw it all together for something that’s easier to copy/paste.

# #   Delete all schedule history for a Schedule # $db = "C:\ProgramData\Admin Arsenal\PDQ Deploy\Database.db" # Get Schedule ID from Schedule Name $ScheduleName = "Heartbeast" $sql = "SELECT ScheduleID FROM Schedules WHERE Name like '$ScheduleName';" $ScheduleID = sqlite3.exe $db $sql # Get target names from ScheduleId $sql = "select Name from ScheduleComputers where Scheduleid = $ScheduleId;" $Computers = sqlite3.exe $db $sql # Remove schedule history for each target and scheduleid) foreach ($Target in $Computers) {    pdqdeploy deleteschedulehistory -Computer $Target -Schedule $ScheduleID }

Wrapping up

Now, you can go delete those target histories like it’s your job… since it very well may actually be your job. In which case, good job! Happy PowerShelling!

Loading...

Black and White PDQ logo
Kris Powell

Kris was an employee at PDQ.

Related articles