PDQ.com mobilePDQ.com desktop

Delete all Target History from a Schedule

Kris PowellKris Powell

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

Summer is almost over. Those of you who work in education may be feeling the stress of back-to-school related responsibilities. PDQ.com is here for you. We’ve got your back. (Unless you need a glass of whiskey, then you’re on your own there.)

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.

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.When

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

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)

Delete all Target History from a Schedule

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"

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

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

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

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! See this in action in a short video:

Ready to put the PowerShell Scanner through its paces?

Take our 14-day Free Trial. Feel the power of the PowerShell scanner.
Start a Trial

Don't miss the next post!

(CVE-2020-1472) 'ZeroLogon' Vulnerability

The Zerologon Vulnerability Allows Attackers To Completely Take Over Your Domain Controller Without Credentials.

© 2020 PDQ.com Corporation


  • PDQ Deploy
  • PDQ Inventory
  • PDQ Link
  • Enterprise SL
  • Pricing
  • Downloads
  • Licensing
  • Buy