question

FrankvanGraafeiland-1586 avatar image
0 Votes"
FrankvanGraafeiland-1586 asked SadiqhAhmed-MSFT commented

AzRecoveryServicesBackupSchedulePolicyObject with custom time

Hi there,

I've been working on a PowerShell script which includes setting an Azure Recovery Vault backup policy. Microsoft has provided an example of how to configure a schedule for such a policy here https://docs.microsoft.com/en-us/powershell/module/az.recoveryservices/new-azrecoveryservicesbackupprotectionpolicy?view=azps-5.9.0.
This includes getting an AzRecoveryServicesBackupSchedulePolicyObject, clearing its ScheduleRunTimes, and adding the current time with the help of Get-Date; that's great, if you want the backups to start at the current time. But, what if you want the backups to be scheduled for a different time?

This is the part of the script that I am struggling with:
$rsvSchedulePolicy = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "AzureVM"
$rsvSchedulePolicy.ScheduleRunTimes.Clear()
$rsvSchedulePolicy.ScheduleRunTimes.Add({16-5-2021 02:00:00})

I can't find anything about how you would enter a different time, and as you can see, I tried just entering a System.String in the same format as the SchedulePolicyObject.ScheduleRunTimes, but the parameter only accepts "Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.SchedulePolicyBase" objects.

Perhaps setting a schedule time different from the current time simply isn't possible with PowerShell. But I highly doubt that.
Any help with this will be greatly appreciated.

Thanks in advance.
Frank

azure-backup
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

FrankvanGraafeiland-1586 avatar image
0 Votes"
FrankvanGraafeiland-1586 answered SadiqhAhmed-MSFT commented

I think I found the answer here https://docs.microsoft.com/en-us/azure/backup/backup-azure-vms-automation.
Apparently, you can just specify a date when you use the Get-Date cmdlet. This is what I wanted:
$rsvSchedulePolicy = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType "AzureVM"
$UtcTime = Get-Date -Date "2021-01-01 04:00:00Z"
$UtcTime = $UtcTime.ToUniversalTime()
$rsvSchedulePolicy.ScheduleRunTimes[0] = $UtcTime

I hope this can help someone in the future.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@FrankvanGraafeiland-1586 Thanks for the update! Glad to hear you were able to find an answer to your issue. The solution you shared would certainly be helpful to others on this community.

0 Votes 0 ·