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