From 19b645bccc1ac38d7ba7f3ad2fa511976ab5d3b9 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 15 Jul 2019 11:48:47 -0400 Subject: [PATCH] Exclude Common Parameters in Filter String --- .../Private/Get-ZertoApiFilter.ps1 | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 b/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 index a6400ca..c4253ca 100644 --- a/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 +++ b/ZertoApiWrapper/Private/Get-ZertoApiFilter.ps1 @@ -1,22 +1,41 @@ function Get-ZertoApiFilter { [cmdletbinding()] + [Outputtype([String])] param( [Parameter( Mandatory = $true, HelpMessage = "Hashtable that contains filter keys and values" )] + [ValidateNotNullOrEmpty()] [hashtable]$filterTable ) # Define the start of the return string [string]$returnString = "?" - + $commonParameters = @( + "Debug" + "ErrorAction" + "ErrorVariable" + "InformationAction" + "InformationVariable" + "OutVariable" + "OutBuffer" + "PipelineVariable" + "Verbose" + "WarningAction" + "WarningVariable" + "WhatIf" + "Confirm" + ) #Foreach item in the table, process each item foreach ( $key in $filterTable.Keys ) { - #If this is not the first item added to the string, add the ampersand and filter - if ($returnString.Length -gt 1) { - $returnString = "{0}&{1}={2}" -f $returnString, $key, $filterTable[$key] - } else { - #If it is the first item, just add the first item - $returnString = "{0}{1}={2}" -f $returnString, $key, $filterTable[$key] + # If the key is not a common parameter, process it. + if ($key -notin $commonParameters) { + #If this is not the first item added to the string, add the ampersand and filter + if ($returnString.Length -gt 1) { + $returnString = "{0}&{1}={2}" -f $returnString, $key, $filterTable[$key] + } else { + #If it is the first item, just add the first item + $returnString = "{0}{1}={2}" -f $returnString, $key, $filterTable[$key] + } } } # Return the built query String