From 8c9babd9d56ae22c855b1c36fc98599986b01f88 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sat, 6 Apr 2019 23:33:14 -0400 Subject: [PATCH] Update Invoke-ZertoMoveCommit.ps1 Add ShouldProcess Use switches instead of bools Prioritize Reverse Protect over KeepSourceVms --- .../Public/Invoke-ZertoMoveCommit.ps1 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ZertoApiWrapper/Public/Invoke-ZertoMoveCommit.ps1 b/ZertoApiWrapper/Public/Invoke-ZertoMoveCommit.ps1 index 59ee712..4c229a4 100644 --- a/ZertoApiWrapper/Public/Invoke-ZertoMoveCommit.ps1 +++ b/ZertoApiWrapper/Public/Invoke-ZertoMoveCommit.ps1 @@ -1,6 +1,6 @@ <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> function Invoke-ZertoMoveCommit { - [cmdletbinding()] + [cmdletbinding(SupportsShouldProcess = $true)] param( [Parameter( HelpMessage = "Name(s) of the VPG(s) to commit.", @@ -10,7 +10,7 @@ function Invoke-ZertoMoveCommit { [Parameter( HelpMessage = "Set this to True to reverse protect the VPG(s) to the source site. If not set, will use selection made during move initiation. True or False" )] - [bool]$reverseProtect, + [switch]$reverseProtection, [Parameter( HelpMessage = "Use this switch to keep the source VMs. If not set, they will be destroyed." )] @@ -19,10 +19,11 @@ function Invoke-ZertoMoveCommit { begin { $baseUri = "vpgs" - if ($reverseProtect) { - $body = @{"ReverseProtection" = $reverseProtect; "KeepSourceVms" = $keepSourceVms} - } else { - $body = @{"KeepSourceVms" = $keepSourceVms} + $body = @{} + if ($reverseProtection) { + $body["ReverseProtection"] = $true + } elseif ($keepSourceVms) { + $body["KeepSourceVms"] = $true } } @@ -33,7 +34,9 @@ function Invoke-ZertoMoveCommit { Write-Error "VPG: $name not found. Please check the name and try again. Skipping." } else { $uri = "{0}/{1}/MoveCommit" -f $baseUri, $vpgId - Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST" + if ($PSCmdlet.ShouldProcess("Commiting VPG: $name with settings $($body | convertto-json)")) { + Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST" + } } } }