diff --git a/Tests/Public/Copy-ZertoVpg.Tests.ps1 b/Tests/Public/Copy-ZertoVpg.Tests.ps1 index 6f0c629..236255e 100644 --- a/Tests/Public/Copy-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Copy-ZertoVpg.Tests.ps1 @@ -17,6 +17,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { @{ParameterName = 'SourceVpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } @{ParameterName = 'NewVpgName'; Type = 'String'; Mandatory = $true; Validation = 'NotNullOrEmpty' } @{ParameterName = 'VMs'; Type = 'String[]'; Mandatory = $true; Validation = 'NotNullOrEmpty' } + @{ParameterName = 'StoragePolicyIdentifier'; Type = 'String'; Mandatory = $false; Validation = 'NotNullOrEmpty' } ) It " parameter is of type" -TestCases $ParameterTestCases { diff --git a/ZertoApiWrapper/Public/Copy-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Copy-ZertoVpg.ps1 index de4f2bc..1f55ee1 100644 --- a/ZertoApiWrapper/Public/Copy-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Copy-ZertoVpg.ps1 @@ -11,11 +11,14 @@ function Copy-ZertoVpg { [Parameter(Mandatory, HelpMessage = "Name to assign the newly created VPG")] [ValidateNotNullOrEmpty()] - [String]$NewVpgName, # Name of VMs to add to the VPG + [String]$NewVpgName, # New VPG Name [Parameter(Mandatory, HelpMessage = "Name(s) of the Virtual Machine(s) to add to the VPG")] [ValidateNotNullOrEmpty()] - [String[]]$VMs + [String[]]$VMs, # Name of VMs to add to the VPG + [Parameter(HelpMessage = "vdcstorageProfile Identifier for VPGs that recover to VCD")] + [ValidateNotNullOrEmpty()] + [String]$StoragePolicyIdentifier ) begin { @@ -23,13 +26,14 @@ function Copy-ZertoVpg { } process { - $VpgIdToCopy = @{ VpgIdentifier = (Get-ZertoVpg -vpgName $SourceVpgName).vpgIdentifier } + $SourceVpg = Get-ZertoVpg -vpgName $SourceVpgName + $VpgIdToCopy = @{ VpgIdentifier = $SourceVpg.vpgIdentifier } if ( $null -eq $VpgIdToCopy.VpgIdentifier ) { Throw "Unable to find a VPG with the name: $SourceVpgName. Please check the name and try again." } $BaseUri = "vpgSettings/copyVpgSettings" - $VmsMap = Get-Map -InputObject (Get-ZertoUnprotectedVm) -Key 'VmName' -Value 'VmIdentifier' - $VmsMap += Get-Map -InputObject (Get-ZertoProtectedVm) -Key 'VmName' -Value 'VmIdentifier' + $VmsMap = Get-Map -InputObject (Get-ZertoUnprotectedVm -site $SourceVpg.protectedsite.identifier) -Key 'VmName' -Value 'VmIdentifier' + $VmsMap += Get-Map -InputObject (Get-ZertoProtectedVm -protectedSiteIdentifier $SourceVpg.protectedsite.identifier) -Key 'VmName' -Value 'VmIdentifier' $VMsToAdd = foreach ($VM in $VMs) { if ($VmsMap.Keys -contains $VM) { [PSCustomObject]@{ @@ -43,11 +47,14 @@ function Copy-ZertoVpg { $NewVpgId = Invoke-ZertoRestRequest -Uri $BaseUri -Body ($VpgIdToCopy | ConvertTo-Json) -Method "POST" $Uri = "{0}/{1}/vms" -f "vpgSettings", $NewVpgId foreach ($VM in $VMsToAdd) { - $null = Invoke-ZertoRestRequest -Uri $Uri -Body ($VM | ConvertTo-Json) -Method "POST" -ErrorAction Stop + $null = Invoke-ZertoRestRequest -Uri $Uri -Body ($VM | ConvertTo-Json) -Method "POST" -ErrorAction Continue } $Uri = "vpgSettings/{0}" -f $NewVpgId $CurrentSettings = Invoke-ZertoRestRequest -Uri $Uri $CurrentSettings.Basic.Name = $NewVpgName + if ($CurrentSettings.Recovery.VCD.OrgVdcIdentifier -ne $null) { + $CurrentSettings.vms[0].Recovery.VCD.StoragePolicyIdentifier = $StoragePolicyIdentifier + } $Null = Invoke-ZertoRestRequest -Uri $Uri -Method "Put" -Body $($CurrentSettings | ConvertTo-Json -Depth 20) Save-ZertoVpgSetting -vpgSettingsIdentifier $NewVpgId } diff --git a/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml b/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml index 51251ea..c188b3f 100644 --- a/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml +++ b/ZertoApiWrapper/Public/en-us/ZertoApiWrapper-help.xml @@ -437,6 +437,208 @@ + + + Copy-ZertoVpg + Copy + ZertoVpg + + Copy an existing VPG settings object to create a new VPG with the same settings. New VMs must be added to the copied VPG. + + + + Copy an existing VPG settings object to create a new VPG with the same settings. New VMs must be added to the copied VPG. + + + + Copy-ZertoVpg + + SourceVpgName + + Name of the VPG to clone + + String + + String + + + None + + + NewVpgName + + Name to assign the newly created VPG + + String + + String + + + None + + + VMs + + Name of VMs to add to the VPG + + String[] + + String[] + + + None + + + StoragePolicyIdentifier + + VCD Storage Profile Identifier for VPGs that recover to VCD + + String + + String + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + + SwitchParameter + + + False + + + + + + NewVpgName + + Name to assign the newly created VPG + + String + + String + + + None + + + SourceVpgName + + Name of the VPG to clone + + String + + String + + + None + + + VMs + + Name of VMs to add to the VPG + + String[] + + String[] + + + None + + + StoragePolicyIdentifier + + VCD Storage Profile Identifier for VPGs that recover to VCD + + String[] + + String[] + + + None + + + Confirm + + Prompts you for confirmation before running the cmdlet. + + SwitchParameter + + SwitchParameter + + + False + + + WhatIf + + Shows what would happen if the cmdlet runs. The cmdlet is not run. + + SwitchParameter + + SwitchParameter + + + False + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + PS C:\> Copy-ZertoVpg -SourceVpgName 'MyVpg' -NewVpgName 'MyNewVpg' -VMs 'VmToAdd01' + + Copies the settings of 'MyVpg' into a new VPG 'MyNewVpg' adding one VM, 'VmToAdd01' + + + + -------------------------- Example 2 -------------------------- + PS C:\> Copy-ZertoVpg -SourceVpgName 'MyVpg' -NewVpgName 'MyNewVpg' -VMs 'VmToAdd01', 'VmToAdd02' + + Copies the settings of 'MyVpg' into a new VPG 'MyNewVpg' adding two VMs, 'VmToAdd01' and 'VmToAdd02' + + + + -------------------------- Example 3 -------------------------- + PS C:\> Copy-ZertoVpg -SourceVpgName 'MyVpg' -NewVpgName 'MyNewVpg' -VMs 'VmToAdd01' -StoragePolicyIdentifier 'urn:vcloud:vdcstorageProfile:00000000-0000-0000-0000-000000000000' + + Copies the settings of 'MyVpg' into a new VPG 'MyNewVpg' adding one VM, 'VmToAdd01', that recovers to VCD with the StoragePolicyIdentifier, 'urn:vcloud:vdcstorageProfile:00000000-0000-0000-0000-000000000000' + + + + + + Online Version: + https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Copy-ZertoVpg.md + + + Zerto Clone VPG API Endpoint Documentation + http://s3.amazonaws.com/zertodownload_docs/Latest/Zerto%20Virtual%20Replication%20Zerto%20Virtual%20Manager%20%28ZVM%29%20-%20vSphere%20Online%20Help/index.html#page/RestfulAPIs%2FStatusAPIs.5.119.html%23 + + + Disconnect-ZertoServer