Archive for October, 2020
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.