This script creates a Windows Scheduled Task to automate the backup of key files daily. Modify it to fit specific directories and scheduling requirements.
# Define parameters
$backupScriptPath = "C:\Scripts\DailyBackupScript.ps1" # Path to the backup script
$taskName = "DailyFileBackup"
$triggerTime = "03:00" # Schedule time in HH:mm format
# Create the scheduled task action
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File `"$backupScriptPath`""
# Define the task trigger (daily at specified time)
$trigger = New-ScheduledTaskTrigger -Daily -At (Get-Date -Format "yyyy-MM-ddT$triggerTime:00.0000000")
# Register the scheduled task
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskName -Description "Daily file backup task"
Write-Output "Scheduled task '$taskName' created to run daily at $triggerTime"
• Explanation: This script creates a scheduled task to run a specified PowerShell backup script daily at a defined time.