PowerShell: Create a Repetitive Scheduled Task for Shadow Copy

The following article describes how to create a scheduled task that creates Shadow Copies in Windows 10. The scheduled task will run daily and at 8:00AM and every 4 hours for a total of 8 hours.

Here are is the PowerShell code that does it:

# Create a scheduled task
$taskAction = New-ScheduledTaskAction -Execute "wmic.exe" -Argument "shadowcopy call create Volume=C:\"
 
# Set how many times the task runs daily and its frequencey
$taskTrigger = New-ScheduledTaskTrigger -Daily -At 8am
$taskTrigger.Repetition = $(New-ScheduledTaskTrigger -Once -At "08:00" -RepetitionDuration "8:00" -RepetitionInterval "04:00").Repetition
 
# Task owner is SYSTEM account and task runs wether user is logged on or not
$taskPrincipal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
 
# Task settings to wake device, to run hidden and to allow to run on battery
$taskSettings = New-ScheduledTaskSettingsSet -WakeToRun -Hidden -AllowStartIfOnBatteries
 
# Setup scheduled task object
$scheduledTask = New-ScheduledTask -Principal $taskPrincipal -Action $taskAction -Trigger $taskTrigger -Settings $taskSettings
 
# Register scheduled task based on setup information gathered from $scheduledTask variable
Register-ScheduledTask "Daily Shadow Copy" -InputObject $scheduledTask

Next the screenshots of the result when the code is executed.

Task general properties. Note that it runs with the SYSTEM account.
We use WMIC to create a volume shadow copy for C:\
Here’s the trigger/schedule information for the task
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: