powershell - backup every 4 hours

Martin_01 used Ask the Experts™
I need to make backups of my system state on my windows 2016 server hyper-v domain controller. The only way for this to work is thru power shell. I am only able to run this for one time. How do I write this t run every 4 hours in PowerShell?

# Runs  from PS on DC1
Register-ScheduledJob -Name “System State Backup” -Trigger @{Frequency = “Daily”; At = “2:00”} -ScriptBlock {
	# Create new Backup Policy
	$Policy = New-WBPolicy

	# Add System State to the policy
	Add-WBSystemState -Policy $Policy

	# Set Backup Location
	$BackupLocation = New-WBBackupTarget -VolumePath "\\bugsbunny\svrA"

	# Add backup location to policy
	Add-WBBackupTarget -Policy $Policy -Target $BackupLocation

	# Start Backup Using Policy
	Start-WBBackup -Policy $Policy

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
RobertSystem Admin

If the scheduled job is not working  it could be that since your not passing credentials the scheduled job is not able to run.


You could just save the script as a ps1 and schedule it via task scheduler.
Distinguished Expert 2018

if you are doing AD system state backup with windows server backup, you can simply use GUI to schedule backup every 4 HRS

If this is core server you can use command line option
wbadmin enable backup -addtarget:F: -schedule:00:00,04:00,08:00,12:00,16:00,20:00 -systemState -quiet 

Open in new window

Jose Gabriel Ortega CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Just add -RunEvery (New-Timespan -hours 4) to your Register-ScheduledJob.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial