PowerShell: Encoding and Decoding of URL

 

URL Encoding:

URLs can only be sent over the Internet using the ASCII character-set.

Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.

URL encoding replaces unsafe ASCII characters with a “%” followed by two hexadecimal digits.

URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.

PowerShell Code:

We can achieve the URL encoding using PowerShell. Please find the piece of code for the same

$URL = Read-Host “Enter URL to Decode”  $Encode = [System.Web.HttpUtility]::UrlEncode($URL)
WriteHost “This is the Encoded URL” $Encode ForegroundColor Green

The same can be decoded using the below PowerShell code.

$Decode = [System.Web.HttpUtility]::UrlDecode($Encode)
$Decode
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s