Functions/ConvertFrom-UrlEncode.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
function ConvertFrom-UrlEncode { <# .SYNOPSIS Converts a URL encoded string back into a normal string .DESCRIPTION Converts a URL encoded string back into a normal string .PARAMETER URL The encoded URL string. Can be a string or an array of strings. Accepts pipeline input. .PARAMETER IncludeInput A switch to enable showing original text in the output. Aliased to 'IncludeOriginal' for backward compatibility of scripts .EXAMPLE ConvertFrom-UrlEncode -URL 'https%3a%2f%2fwww.google.com%2f' Would return https://www.google.com/ .EXAMPLE ConvertFrom-UrlEncode -URL 'https%3a%2f%2fbing.com' -IncludeInput Would return Encoded Decoded ------- ------- https%3a%2f%2fbing.com https://bing.com .EXAMPLE ConvertFrom-UrlEncode -URL 'https%3a%2f%2fbing.com', 'https%3a%2f%2fwww.google.com%2f' -IncludeInput Would return Encoded Decoded ------- ------- https%3a%2f%2fbing.com https://bing.com https%3a%2f%2fwww.google.com%2f https://www.google.com/ .OUTPUTS [string] #> [CmdletBinding(ConfirmImpact = 'None')] [alias('UrlDecode')] [OutputType('string')] Param( [Parameter(ValueFromPipeline)] [string[]] $URL, [Alias('IncludeOriginal')] [switch] $IncludeInput ) begin { Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]" } process { foreach ($currentURL in $URL) { $Decode = [System.Web.HttpUtility]::UrlDecode($currentURL) if ($IncludeInput) { New-Object -TypeName 'psobject' -Property ([ordered] @{ Encoded = $currentURL Decoded = $Decode }) } else { Write-Output -InputObject $Decode } } } end { Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]" } } |