Functions/Data/Convert-HashToEncodedHash.ps1
Function Convert-HashToEncodedHash { [CmdletBinding()] Param ( # Request Parameter Hashtable [Parameter(Mandatory=$true,ValueFromPipeLine=$True)] [hashtable] $Hash, # Strict Ordering [Parameter(Mandatory=$false)] [boolean] $Ordered = $True ) Process { # Switch on Ordering Param switch ($Ordered) { $true { $EncodedHash = [ordered]@{} $Keys = $Hash.Keys | select @{n="key";e={$_}},@{n="encKey";e={ConvertTo-URLEncoding $_}} | sort EncKey $Keys | foreach {$EncodedHash.Add(($_.EncKey),(ConvertTo-URLEncoding $RequestHash[$_.Key]))} } $false { $EncodedHash = @{} $Keys | foreach {$EncodedHash.Add((ConvertTo-URLEncoding $_),(ConvertTo-URLEncoding $RequestHash.$_))} } } # Output Encoded Hash $EncodedHash } } |