Schedule Weekly PDQ Deploy and Inventory Database Maintenance with Server Reboot
This article shows how to create a Windows Scheduled Task on your PDQ server that performs weekly database optimization for both PDQ Deploy and PDQ Inventory and then reboots the server.
Running regular database maintenance can help keep the PDQ databases performing efficiently, while a scheduled reboot can clear stale processes and apply any pending Windows updates.
Database optimization will terminate all actively running deployments or scans on your PDQ server.
Prerequisites
- Administrator access to the PDQ server
- PDQ Deploy installed
- PDQ Inventory installed
- A planned maintenance window when deployments and scans are not expected to run
Create the Maintenance Script
- Open Notepad.
- Paste the following contents:
@echo off echo ==== %date% %time% ==== >> C:\Scripts\PDQMaintenance.log pdqdeploy optimizedatabase >> C:\Scripts\PDQMaintenance.log 2>&1 pdqinventory optimizedatabase >> C:\Scripts\PDQMaintenance.log 2>&1 shutdown /r /f /t 0
- Save the file as:
C:\Scripts\PDQWeeklyMaintenance.bat
If the C:\Scripts folder does not exist, create it before saving the file.
Create the Scheduled Task
You can create the scheduled task manually using Task Scheduler, or automatically by running the following PowerShell script from an elevated PowerShell session. Update the schedule variables before running the script to match your maintenance window.
<# .INSTRUCTIONS 1. Modify $DayOfWeek to the day you want maintenance to occur. Valid values: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday 2. Modify $StartTime to the desired maintenance window start time. Examples: '01:00AM' '03:30AM' '11:00PM' 3. If you saved the maintenance batch file to a different location, update $ScriptPath accordingly. .NOTES - The scheduled task runs as SYSTEM. - The scheduled task runs with the highest privileges. - If a maintenance task is already running, additional instances are ignored. - Missed scheduled runs are NOT started automatically later, preventing unexpected reboots outside the maintenance window. #> # Configuration $TaskName = 'PDQ Weekly Maintenance' $ScriptPath = 'C:\Scripts\PDQWeeklyMaintenance.bat' # Schedule Settings $DayOfWeek = 'Sunday' $StartTime = '03:00AM' $Action = New-ScheduledTaskAction -Execute $ScriptPath $Trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $DayOfWeek -At $StartTime $Settings = New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Settings $Settings -User 'SYSTEM' -RunLevel Highest -Force Write-Host "Scheduled task '$TaskName' created successfully." -ForegroundColor Green Write-Host "Schedule: Every $DayOfWeek at $StartTime" -ForegroundColor Green
If PowerShell is unavailable or you prefer to use the graphical interface instead, create the scheduled task manually using the following steps.
- Open Task Scheduler.
- Select Create Task.
- On the General tab:
- Enter PDQ Weekly Maintenance for the task name.
- Click Change User or Group... and enter SYSTEM as the user ID.
- Click OK.
- Select Run with highest privileges.
- Select the Triggers tab, then click New.
- Configure the trigger:
- Begin the task: On a schedule
- Settings: Weekly
- Select the desired day and time for maintenance.
- Click OK.
- Select the Actions tab.
- Click New.
- Configure the action:
- Action: Start a program
- Program/script:
C:\Scripts\PDQWeeklyMaintenance.bat
- Click OK.
Notes
- Schedule the task during off-hours to minimize disruption to deployments, scans, and console users.
- Inform other PDQ administrators of the maintenance window and reboot schedule.
- Avoid scheduling maintenance during recurring deployments, scans, backups, or other server maintenance activities.
- Depending on database size, the optimization process may take several minutes to complete before the reboot begins.