Various fixes
Removed Commit Value as it is not a vaild param Enabled ShouldProcess Ensured mandatory default values make it into the body Added Validate a valid VPG is selected.
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
|
||||
function Invoke-ZertoFailover {
|
||||
[cmdletbinding()]
|
||||
[cmdletbinding( SupportsShouldProcess = $true )]
|
||||
param(
|
||||
[Parameter(
|
||||
Mandatory = $true,
|
||||
HelpMessage = "Name of the VPG to Failover"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$vpgName,
|
||||
[Parameter(
|
||||
HelpMessage = "Checkpoint Identifier to use as the Point-In-Time to rollback to."
|
||||
)]
|
||||
[Alias("checkpointId")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$checkpointIdentifier,
|
||||
[Parameter(
|
||||
HelpMessage = "'Rollback': After the seconds specified in the commitValue setting have elapsed, the failover is rolled back.
|
||||
@@ -19,11 +21,7 @@ function Invoke-ZertoFailover {
|
||||
Default is the Site Settings setting."
|
||||
)]
|
||||
[ValidateSet("Rollback", "Commit", "None")]
|
||||
[string]$commitPolicy,
|
||||
[Parameter(
|
||||
HelpMessage = "The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. Default is the Site Setting"
|
||||
)]
|
||||
[string]$commitValue,
|
||||
[string]$commitPolicy = "Rollback",
|
||||
[Parameter(
|
||||
HelpMessage = "0: The protected virtual machines are not touched before starting the failover. This assumes that you do not have access to the protected virtual machines. -- DEFAULT
|
||||
1: If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the virtual machines are gracefully shut down, otherwise the failover operation fails. This is similar to performing a Move operation to a specified checkpoint.
|
||||
@@ -32,9 +30,9 @@ function Invoke-ZertoFailover {
|
||||
[ValidateSet(0, 1, 2)]
|
||||
[int]$shutdownPolicy = 0,
|
||||
[Parameter(
|
||||
HelpMessage = "Time, in seconds, before VMs are forcibly turned off if the Force Shutdown option is seclected after attempting to gracefully shut down the VMs"
|
||||
HelpMessage = "The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. Default is 60 Minutes (3600 Seconds)"
|
||||
)]
|
||||
[long]$timeToWaitBeforeShutdownInSec = 300,
|
||||
[int]$timeToWaitBeforeShutdownInSec = 3600,
|
||||
[Parameter(
|
||||
HelpMessage = "True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings.
|
||||
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."
|
||||
@@ -43,15 +41,23 @@ function Invoke-ZertoFailover {
|
||||
[Parameter(
|
||||
HelpMessage = "Name(s) of VMs in the VPG to failover"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string[]]$vmName
|
||||
)
|
||||
|
||||
begin {
|
||||
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
|
||||
$baseUri = "vpgSettings/{0}/failover" -f $vpgId
|
||||
$vpgId = $(Get-ZertoVpg -name $vpgName).vpgIdentifier
|
||||
if ( -not $vpgId) {
|
||||
Write-Error "VPG: $vpgName Not Found. Please check the name and try again!"
|
||||
break
|
||||
}
|
||||
$baseUri = "vpgs/{0}/failover" -f $vpgId
|
||||
$body = [ordered]@{}
|
||||
# Setup Defaults
|
||||
$body['commitpolicy'] = $commitPolicy
|
||||
$body['TimeToWaitBeforeShutdownInSec'] = $timeToWaitBeforeShutdownInSec
|
||||
foreach ($key in $PSBoundParameters.Keys) {
|
||||
if ($key -notlike 'vpgGroup' -or $key -notlike 'vmName') {
|
||||
if ($key -notlike 'vpgName' -and $key -notlike 'vmName' -and $key -notlike 'WhatIf' -and $key -notlike 'TimeToWaitBeforeShutdownInSec' -and $key -notlike 'commitpolicy') {
|
||||
$body[$key] = $PSBoundParameters['key']
|
||||
}
|
||||
}
|
||||
@@ -65,7 +71,10 @@ function Invoke-ZertoFailover {
|
||||
}
|
||||
|
||||
process {
|
||||
Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST"
|
||||
if ($PSCmdlet.ShouldProcess("$vpgName with identifier $vpgId and these options $($body | convertto-json)")) {
|
||||
Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
Reference in New Issue
Block a user