diff --git a/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 index 3645ec7..38ec249 100644 --- a/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 @@ -1,37 +1,72 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Remove-ZertoVpg { - [cmdletbinding( SupportsShouldProcess = $true )] + [cmdletbinding( SupportsShouldProcess = $true, DefaultParameterSetName = "vpgIdentifier" )] param( [Parameter( Mandatory = $true, - HelpMessage = "Name of the VPG to delete." + ParameterSetName = "vpgName", + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + HelpMessage = "Name(s) of the VPG(s) to delete." )] - [string]$vpgName, + [string[]]$vpgName, + [Parameter( + Mandatory = $true, + ParameterSetName = "vpgIdentifier", + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + HelpMessage = "vpgIdentifier(s) of the VPG(s) to delete." + )] + [string[]]$vpgidentifier, [Parameter( HelpMessage = "Use this parameter to keep the recovery volumes at the target site, by setting it to True. If the virtual machines in the deleted VPG are reprotected, these volumes can be used as preseeded volumes to speed up the initial synchronization of the new VPG. Default is to remove Recovery Volumes" )] - [bool]$keepRecoveryVolumes = $false, + [switch]$keepRecoveryVolumes = $false, [Parameter( HelpMessage = "Use this parameter to force delete the VPG, by setting this parameter equal to true." )] - [bool]$force = $false + [switch]$force = $false ) begin { $baseUri = "vpgs" - $vpgIdentifier = $(get-zertovpg -name $vpgName).vpgIdentifier + $body = @{} + if ($keepRecoveryVolumes) { + $body['KeepRecoveryVolumes'] = $True + } else { + $body['KeepRecoveryVolumes'] = $False + } + if ($force) { + $body['force'] = $True + } else { + $body['force'] = $False + } } process { - $vpgIdentifier = $(get-zertovpg -name $vpgName).vpgIdentifier - if ( $vpgIdentifier ) { - $uri = "{0}/{1}" -f $baseUri, $vpgIdentifier - $body = @{"Force" = $force; "KeepRecoveryVolumes" = $keepRecoveryVolumes} - if ($PSCmdlet.ShouldProcess( $vpgName + " and these settings: " + $($body | ConvertTo-Json) ) ) { - Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -Method "DELETE" + switch ($PSCmdlet.ParameterSetName) { + "vpgName" { + foreach ($name in $vpgName) { + $id = $(get-zertovpg -name $name).vpgIdentifier + if ($id) { + $uri = "{0}/{1}" -f $baseUri, $id + if ($PSCmdlet.ShouldProcess( $name + " and these settings: " + $($body | ConvertTo-Json) ) ) { + Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -Method "DELETE" + } + } else { + Write-Output "VPG with name $vpgName not found. Please check the name and try again" + } + } + } + + "vpgIdentifier" { + foreach ($id in $vpgIdentifier) { + $uri = "{0}/{1}" -f $baseUri, $id + if ($PSCmdlet.ShouldProcess( $id + " and these settings: " + $($body | ConvertTo-Json) ) ) { + Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -Method "DELETE" + } + } } - } else { - Write-Output "VPG with name $vpgName not found. Please check the name and try again" } }