From 33b9db8e0094af3cdcedbb3a7bd763d0c8622c38 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Wed, 27 Feb 2019 16:59:47 -0500 Subject: [PATCH] Build Invoke-ZertoMove --- ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 | 78 +++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 index e69de29..50373a0 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoMove.ps1 @@ -0,0 +1,78 @@ +function Invoke-ZertoMove { + [CmdletBinding()] + param( + [Parameter( + HelpMessage = "Name(s) of the VPG(s) you want to move.", + Mandatory = $true + )] + [string[]]$vpgName, + [Parameter( + HelpMessage = "The policy to use after the move enters a 'Before Commit' state. If omitted, the site settings default will be applied. Valid values are: '0' or 'Rollback', '1' or 'Commit', '2' or 'None'. Please see Zerto API Documentation for additional information." + )] + [string]$commitPolicy, + [Parameter( + HelpMessage = "The amount of time, in seconds, the Move is in a 'Before Commit' state, before performing the commitPolicy setting. If omitted, the site settings default will be applied." + )] + [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" + )] + [bool]$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." + )] + [bool]$reverseProtection = $false, + [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" + )] + [bool]$keepSourceVms = $false, + [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" + )] + [bool]$continueOnPreScriptFailure + ) + + begin { + $baseUri = "vpgs" + $body = [ordered]@{} + if ($PSBoundParameters.ContainsKey('commitPolicy')) { + $body['commitPolicy'] = $commitPolicy + } + if ($PSBoundParameters.ContainsKey('commitPolicyTimeout')) { + $body['commitPolicyTimeout'] = $commitPolicyTimeout + } + if ($PSBoundParameters.ContainsKey('forceShutdown')) { + $body['forceShutdown'] = $forceShutdown + } + if ($PSBoundParameters.ContainsKey('reverseProtection')) { + $body['reverseProtection'] = $reverseProtection + } + if ($PSBoundParameters.ContainsKey('keepSourceVms')) { + $body['keepSourceVms'] = $keepSourceVms + } + if ($PSBoundParameters.ContainsKey('continueOnPreScriptFail')) { + $body['continueOnPreScriptFail'] = $continueOnPreScriptFailure + } + } + + process { + foreach ($name in $vpgName) { + $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier + $uri = "{0}/{1}/move" -f $baseUri, $vpgId + Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) + } + } + + end { + # Nothing to do. + } +} \ No newline at end of file