public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; // initialize values to default DateTime rangeStart = DateTime.UtcNow.AddDays(-1); DateTime rangeEnd = DateTime.UtcNow; if (From.HasValue) { rangeStart = From.Value; } if (!From.HasValue && To.HasValue) { throw new Exception(Resources.JobFromNotProvided); } if (To.HasValue) { rangeEnd = To.Value; } if (rangeStart.Kind != DateTimeKind.Utc || rangeEnd.Kind != DateTimeKind.Utc) { throw new Exception(Resources.JobTimeFiltersShouldBeSpecifiedInUtc); } // validate filters if (rangeEnd <= rangeStart) { throw new Exception(Resources.JobToShouldBeGreaterThanFrom); } else if (rangeEnd.Subtract(rangeStart) > TimeSpan.FromDays(30)) { throw new Exception(Resources.JobAllowedDateTimeRangeExceeded); } else if (rangeStart > DateTime.UtcNow) { throw new Exception(Resources.JobStartTimeShouldBeLessThanCurrent); } // validate JobId and Job objects if (!string.IsNullOrEmpty(JobId)) { // if JobId and Job are provided together and they don't match then throw exception if (Job != null && JobId != Job.JobId) { throw new Exception(Resources.JobJobIdAndJobMismatch); } } else if (Job != null) { JobId = Job.JobId; } List <JobBase> result = new List <JobBase>(); WriteDebug(string.Format("Filters provided are: StartTime - {0} " + "EndTime - {1} Status - {2} Operation - {3} Type - {4} UseSecondaryRegion - {5}", From, To, Status, Operation, BackupManagementType, UseSecondaryRegion.ToString())); int resultCount = 0; if (UseSecondaryRegion.IsPresent) { ARSVault vault = ServiceClientAdapter.GetVault(resourceGroupName, vaultName); string secondaryRegion = BackupUtils.regionMap[vault.Location]; WriteDebug(" Getting CRR jobs from secondary region: " + secondaryRegion); var adapterResponse = ServiceClientAdapter.GetCrrJobs(VaultId, JobId, ServiceClientHelpers.GetServiceClientJobStatus(Status), Operation.ToString(), rangeStart, rangeEnd, ServiceClientHelpers.GetServiceClientBackupManagementType(BackupManagementType), secondaryRegion); JobConversions.AddServiceClientJobsToPSList( adapterResponse, result, ref resultCount); } else { var adapterResponse = ServiceClientAdapter.GetJobs( JobId, ServiceClientHelpers.GetServiceClientJobStatus(Status), Operation.ToString(), rangeStart, rangeEnd, ServiceClientHelpers.GetServiceClientBackupManagementType( BackupManagementType), vaultName: vaultName, resourceGroupName: resourceGroupName); JobConversions.AddServiceClientJobsToPSList( adapterResponse, result, ref resultCount); } WriteDebug("Number of jobs fetched: " + result.Count); WriteObject(result, enumerateCollection: true); }); }