From e19f9b34f549a9b97ab035502ce84ee21b8f03a0 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 28 Feb 2020 08:15:53 -0500 Subject: [PATCH] Update function to allow pipeline operations --- Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 | 2 +- .../Public/Checkpoint-ZertoVpg.ps1 | 22 +++++++++++-------- docs/Checkpoint-ZertoVpg.md | 6 ++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 b/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 index f580a6f..7ae3eea 100644 --- a/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 +++ b/Tests/Public/Checkpoint-ZertoVpg.Tests.ps1 @@ -16,7 +16,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { Context "$($global:function)::Parameter Unit Tests" { It "Has a parameter for the VpgName that is Mandatory" { - Get-Command $global:function | Should -HaveParameter vpgName -Mandatory -Type String + Get-Command $global:function | Should -HaveParameter vpgName -Mandatory -Type 'String[]' } It "Has a parameter for the CheckpointName that is Mandatory" { diff --git a/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 index e8d94b7..c0dd1a4 100644 --- a/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 @@ -4,10 +4,12 @@ function Checkpoint-ZertoVpg { param( [Parameter( Mandatory = $true, - HelpMessage = "Name of the VPG to tag." + HelpMessage = "Name of the VPG to tag.", + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true )] [ValidateNotNullOrEmpty()] - [string]$vpgName, + [string[]]$vpgName, [Parameter( Mandatory = $true, HelpMessage = "Text to tag the checkpoint with." @@ -18,16 +20,18 @@ function Checkpoint-ZertoVpg { begin { $baseUri = "vpgs" - $vpgIdentifier = $(get-zertovpg -name $vpgName).vpgIdentifier - $body = @{"checkpointName" = $checkpointName} } process { - if ($vpgIdentifier) { - $uri = "{0}/{1}/Checkpoints" -f $baseUri, $vpgIdentifier - Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -method "POST" - } else { - Write-Output "Cannot find VPG named $vpgName. Please check the name and try again." + foreach ($name in $vpgName) { + $vpgIdentifier = $(get-zertovpg -name $name).vpgIdentifier + if ($vpgIdentifier) { + $uri = "{0}/{1}/Checkpoints" -f $baseUri, $vpgIdentifier + $body = @{"checkpointName" = $checkpointName} + Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -method "POST" + } else { + Write-Output "Cannot find VPG named $name. Please check the name and try again." + } } } diff --git a/docs/Checkpoint-ZertoVpg.md b/docs/Checkpoint-ZertoVpg.md index d7cfbf5..7951d3c 100644 --- a/docs/Checkpoint-ZertoVpg.md +++ b/docs/Checkpoint-ZertoVpg.md @@ -13,7 +13,7 @@ Add a tagged checkpoint to a specified VPG ## SYNTAX ``` -Checkpoint-ZertoVpg [-vpgName] [-checkpointName] [] +Checkpoint-ZertoVpg [-vpgName] [-checkpointName] [] ``` ## DESCRIPTION @@ -49,14 +49,14 @@ Accept wildcard characters: False Name of the VPG to tag. ```yaml -Type: String +Type: String[] Parameter Sets: (All) Aliases: Required: True Position: 0 Default value: None -Accept pipeline input: False +Accept pipeline input: True (ByPropertyName, ByValue) Accept wildcard characters: False ```