public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); string vmName = String.Empty; string rgName = String.Empty; string ServiceOrRG = String.Empty; if (this.ParameterSetName == V1VMParameterSet) { vmName = Name; rgName = ServiceName; WriteDebug(String.Format(Resources.RegisteringARMVM1, vmName, rgName)); ServiceOrRG = "CloudServiceName"; } else if (this.ParameterSetName == V2VMParameterSet) { vmName = Name; rgName = ResourceGroupName; WriteDebug(String.Format(Resources.RegisteringARMVM2, vmName, rgName)); ServiceOrRG = "ResourceGroupName"; } else { throw new PSArgumentException(Resources.PSArgumentException); //TODO: PM scrub needed } Guid jobId = Guid.Empty; bool isDiscoveryNeed = false; CSMContainerResponse container = null; isDiscoveryNeed = IsDiscoveryNeeded(vmName, rgName, out container); if (isDiscoveryNeed) { WriteDebug(String.Format(Resources.VMNotDiscovered, vmName)); RefreshContainer(Vault.ResourceGroupName, Vault.Name); isDiscoveryNeed = IsDiscoveryNeeded(vmName, rgName, out container); if ((isDiscoveryNeed == true) || (container == null)) { //Container is not discovered. Throw exception string errMsg = String.Format(Resources.DiscoveryFailure, vmName, ServiceOrRG, rgName); WriteDebug(errMsg); ThrowTerminatingError(new ErrorRecord(new Exception(Resources.AzureVMNotFound), string.Empty, ErrorCategory.InvalidArgument, null)); } } //Container is discovered. Register the container WriteDebug(String.Format(Resources.RegisteringVM, vmName)); var operationId = AzureBackupClient.RegisterContainer(Vault.ResourceGroupName, Vault.Name, container.Name); var operationStatus = GetOperationStatus(Vault.ResourceGroupName, Vault.Name, operationId); WriteObject(GetCreatedJobs(Vault.ResourceGroupName, Vault.Name, Vault, operationStatus.JobList).FirstOrDefault()); }); }