From 4c32bbe057e488b73f99a3ead4695a9e0d086938 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 5 Mar 2020 21:43:32 -0500 Subject: [PATCH 1/2] Update to PwSh Version 7 --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 77c8224..7331185 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,5 @@ "editor.insertSpaces": true, "editor.tabSize": 4, "powershell.codeFormatting.preset": "OTBS", - "terminal.integrated.shell.windows": "c:/Program Files/PowerShell/6/pwsh.exe" + "terminal.integrated.shell.windows": "c:/Program Files/PowerShell/7/pwsh.exe" } From bc02e796d652bc892dfa514a140cd15b90a4e3a6 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 5 Mar 2020 21:43:52 -0500 Subject: [PATCH 2/2] Refactor for DRY --- ZertoApiWrapper/Public/Get-ZertoVpg.ps1 | 28 +++++++++++-------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/ZertoApiWrapper/Public/Get-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Get-ZertoVpg.ps1 index d151152..6990526 100644 --- a/ZertoApiWrapper/Public/Get-ZertoVpg.ps1 +++ b/ZertoApiWrapper/Public/Get-ZertoVpg.ps1 @@ -160,7 +160,6 @@ function Get-ZertoVpg { ) begin { $baseUri = "vpgs" - $returnObject = @() } Process { @@ -169,14 +168,13 @@ function Get-ZertoVpg { # When called with no parameters, return all values "main" { - $returnObject = Invoke-ZertoRestRequest -uri $baseUri + $uri = $baseUri } # When called with protectionGroupIdentifier, query for each id provided "protectionGroupIdentifier" { - $returnObject = foreach ( $vpgId in $protectionGroupIdentifier ) { - $uri = "{0}/{1}" -f $baseUri, $vpgId - Invoke-ZertoRestRequest -uri $uri + $uri = foreach ( $vpgId in $protectionGroupIdentifier ) { + "{0}/{1}" -f $baseUri, $vpgId } } @@ -185,7 +183,7 @@ function Get-ZertoVpg { $filter = $false if ( $PSBoundParameters.ContainsKey("startDate") -or $PSBoundParameters.ContainsKey("endDate") ) { $filter = $true - $filterTable = @{} + $filterTable = @{ } foreach ( $param in $PSBoundParameters.GetEnumerator() ) { if ( $param.key -eq "startDate" -or $param.key -eq "endDate") { $filterTable[$param.key] = $param.value @@ -193,21 +191,19 @@ function Get-ZertoVpg { } $filter = Get-ZertoApiFilter -filterTable $filterTable } - $returnObject = foreach ( $id in $protectionGroupIdentifier ) { + $uri = foreach ( $id in $protectionGroupIdentifier ) { if ( $filter ) { - $uri = "{0}/{1}/checkpoints{2}" -f $baseUri, $id, $filter + "{0}/{1}/checkpoints{2}" -f $baseUri, $id, $filter } else { - $uri = "{0}/{1}/checkpoints" -f $baseUri, $id + "{0}/{1}/checkpoints" -f $baseUri, $id } - Invoke-ZertoRestRequest -uri $uri } } # When stats are requested "stats" { - $returnObject = foreach ( $id in $protectionGroupIdentifier ) { - $uri = "{0}/{1}/checkpoints/stats" -f $baseUri, $id - Invoke-ZertoRestRequest -uri $uri + $uri = foreach ( $id in $protectionGroupIdentifier ) { + "{0}/{1}/checkpoints/stats" -f $baseUri, $id } } @@ -215,18 +211,18 @@ function Get-ZertoVpg { "filter" { $filter = Get-ZertoApiFilter -filterTable $PSBoundParameters $uri = "{0}{1}" -f $baseUri, $filter - $returnObject = Invoke-ZertoRestRequest -uri $uri } # Default is to build URI based on ParameterSetName and return results. default { $uri = "{0}/{1}" -f $baseUri, $PSCmdlet.ParameterSetName.ToLower() - $returnObject = Invoke-ZertoRestRequest -uri $uri } } + foreach ($entry in $uri) { + Invoke-ZertoRestRequest -uri $entry + } } End { - return $returnObject } }