Classes/TMASRReplication.ps1
using namespace Microsoft.Azure.Commands.RecoveryServices using namespace Microsoft.Azure.Commands.Network.Models using namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery using namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels class TMASRReplication { [String]$SourceMachineName [String]$TargetMachineName [String]$TargetSubnet [String]$DiskType [ARSVault]$TargetVault [PSResourceGroup]$TargetResourceGroup [PSVirtualNetwork]$TargetVirtualNetwork [ASRProtectionContainerMapping]$TargetContainerMap [ASRFabric]$Fabric [ASRProtectionContainer]$ProtectionContainer [ASRProtectableItem]$ProtectableVM static [ASRJob]$ReplicationJob TMASRReplication() {} TMASRReplication([String]$SourceMachineName) { $this.SourceMachineName = $SourceMachineName $this.TargetMachineName = $SourceMachineName } [void] StartReplicationJob() { $ReplicationJobSplat = @{ VMwareToAzure = $true ProtectableItem = $this.ProtectableVM Name = [Guid]::NewGuid().Guid ProtectionContainerMapping = $this.TargetContainerMap DiskType = $this.DiskType ProcessServer = $this.Fabric.FabricSpecificDetails.ProcessServers[0] Account = $this.Fabric.FabricSpecificDetails.RunAsAccounts[0] RecoveryResourceGroupId = $this.TargetResourceGroup.ResourceId RecoveryAzureNetworkId = $this.TargetVirtualNetwork.Id RecoveryAzureSubnetName = $this.TargetSubnet RecoveryVmName = $this.TargetMachineName # -LogStorageAccountId $targetPostFailoverLogStorageAccount.Id ` } $this.ReplicationJob = New-AzRecoveryServicesAsrReplicationProtectedItem @ReplicationJobSplat - } [void] SetAndEnsureVaultContext() { Write-Host "Ensuring services vault context" $this.TargetVault = Get-AzRecoveryServicesVault if (($null -eq $this.TargetVault) -or ($this.TargetVault.Count -gt 1)) { Write-Error "Unable to find vault without a provided name" } [void](Set-AzRecoveryServicesAsrVaultContext -Vault $this.TargetVault) } [void] SetProtectionContainer() { Write-Host "Setting protection container reference for fabric server '$($this.Fabric.Name)-$($this.Fabric.FriendlyName)'" $this.ProtectionContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $this.Fabric } [void] SetProtectionContainer([ASRFabric]$Fabric) { Write-Host "Setting protection container reference for fabric server '$($Fabric.Name)-$($Fabric.FriendlyName)'" $this.ProtectionContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $Fabric } [void] SetProtectableItem() { $_protectableItem = [TMASRCommon]::GetProtectableItem($this.ProtectionContainer, $this.SourceMachineName) Write-Host "Setting protectable item reference '$($this.SourceMachineName)'" $this.ProtectableVM = $_protectableItem } # [PSObject] GetProtectedItemFromVault([String]$VaultName, [String]$SourceMachineName, [String]$SourceConfigurationServer) { # $vaultServer = $this.GetAndEnsureVaultContext($VaultName) # $FabricServer = $this.GetFabricServer($SourceConfigurationServer) # # $ProtectionContainer = $this.GetProtectionContainer($FabricServer) # $protectableVM = $this.GetProtectableItem($ProtectionContainer, $SourceMachineName) # Write-Host "ProtectableStatus: '$($protectableVM.ProtectionStatus)'" # if ($protectableVM.ReplicationProtectedItemId -ne $null) { # $ProtectedItem = $this.GetProtectedItem($ProtectionContainer, $SourceMachineName) # Write-Host "ProtectionState: '$($ProtectedItem.ProtectionState)'" # Write-Host "ProtectionDescription: '$($ProtectedItem.ProtectionStateDescription)'" # return $ProtectedItem # } else { # Write-Host "'$($SourceMachineName)' protectable item is not in a protected state ready for replication" # return $null # } # } } |