Update Invoke-ZertoMove.ps1
WhatIf Processing Reverse Protection Logic Ensure Params are set and do not rely on defaults
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
|
||||
function Invoke-ZertoMove {
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding( DefaultParameterSetName = "main", SupportsShouldProcess = $true )]
|
||||
param(
|
||||
[Parameter(
|
||||
HelpMessage = "Name(s) of the VPG(s) you want to move.",
|
||||
Mandatory = $true
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string[]]$vpgName,
|
||||
[Parameter(
|
||||
HelpMessage = "'Rollback': After the seconds specified in the commitValue setting have elapsed, the failover is rolled back.
|
||||
@@ -20,30 +21,23 @@ function Invoke-ZertoMove {
|
||||
)]
|
||||
[Int32]$commitPolicyTimeout,
|
||||
[Parameter(
|
||||
HelpMessage = "False: If a utility (VMware Tools) is installed on the protected virtual machines, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off.
|
||||
True: To force a shutdown of the virtual machines.
|
||||
Default: True"
|
||||
HelpMessage = "If this switch is specified, Zerto will attempt to gracefully shut down the Virtual Machines. If the machines do not poweroff within 5 minutes, they will be forcibly powering them off."
|
||||
)]
|
||||
[bool]$forceShutdown,
|
||||
[switch]$forceShutdown,
|
||||
[Parameter(
|
||||
HelpMessage = "False: Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set.
|
||||
True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings.
|
||||
Default Value: True
|
||||
Note: If ReverseProtection is set to True, the KeepSourceVMs should be ignored because the virtual disks of the VMs are used for replication and cannot have VMs attached."
|
||||
ParameterSetName = "disableReverseProtection",
|
||||
HelpMessage = "Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set."
|
||||
)]
|
||||
[bool]$reverseProtection = $false,
|
||||
[switch]$disableReverseProtection,
|
||||
[Parameter(
|
||||
HelpMessage = "False: Remove the protected virtual machines from the protected site.
|
||||
True: Prevent the protected virtual machines from being deleted in the protected site.
|
||||
Default: False"
|
||||
ParameterSetName = "keepSourceVms",
|
||||
HelpMessage = "Prevent the protected virtual machines from being deleted in the protected site. Using this setting disables reverse protection."
|
||||
)]
|
||||
[bool]$keepSourceVms = $false,
|
||||
[switch]$keepSourceVms,
|
||||
[Parameter(
|
||||
HelpMessage = "False: Do not continue the Move operation in case of failure of script executing prior the operation.
|
||||
True: Continue the Move operation in case of failure of script executing prior the operation.
|
||||
Default: False"
|
||||
HelpMessage = "Continue the Move operation in case of failure of script executing prior the operation. If this switch is not set a failure of the script executing prior to the operation will cause the operation to fail."
|
||||
)]
|
||||
[bool]$continueOnPreScriptFailure
|
||||
[switch]$ContinueOnPreScriptFailure
|
||||
)
|
||||
|
||||
begin {
|
||||
@@ -57,16 +51,30 @@ function Invoke-ZertoMove {
|
||||
$body['commitPolicyTimeout'] = $commitPolicyTimeout
|
||||
}
|
||||
if ($PSBoundParameters.ContainsKey('forceShutdown')) {
|
||||
$body['forceShutdown'] = $forceShutdown
|
||||
$body['forceShutdown'] = $true
|
||||
} else {
|
||||
$body['forceShutdown'] = $false
|
||||
}
|
||||
if ($PSBoundParameters.ContainsKey('reverseProtection')) {
|
||||
$body['reverseProtection'] = $reverseProtection
|
||||
if ($PSBoundParameters.ContainsKey('ContinueOnPreScriptFailure')) {
|
||||
$body['ContinueOnPreScriptFailure'] = $true
|
||||
} else {
|
||||
$body['ContinueOnPreScriptFailure'] = $false
|
||||
}
|
||||
if ($PSBoundParameters.ContainsKey('keepSourceVms')) {
|
||||
$body['keepSourceVms'] = $keepSourceVms
|
||||
}
|
||||
if ($PSBoundParameters.ContainsKey('continueOnPreScriptFail')) {
|
||||
$body['continueOnPreScriptFail'] = $continueOnPreScriptFailure
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
"disableReverseProtection" {
|
||||
$body['reverseProtection'] = $false
|
||||
$body['keepSourceVms'] = $false
|
||||
}
|
||||
|
||||
"keepSourceVms" {
|
||||
$body['reverseProtection'] = $false
|
||||
$body['keepSourceVms'] = $true
|
||||
}
|
||||
|
||||
"main" {
|
||||
$body['reverseProtection'] = $true
|
||||
$body['keepSourceVms'] = $false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +85,9 @@ function Invoke-ZertoMove {
|
||||
Write-Error "VPG: $name not found. Please check the name and try again. Skipping"
|
||||
} else {
|
||||
$uri = "{0}/{1}/move" -f $baseUri, $vpgId
|
||||
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
|
||||
if ($PSCmdlet.ShouldProcess("Moving VPG: $name wiht settings: $($body | convertto-json)")) {
|
||||
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user