Encode and decode an URL using PowerShell coding

No comments

Here in this post, I will show how to encode and decode the URL using PowerShell coding.


A website’s URL, also usually known as the “website address”, is what we would enter into a web browser in order to access a specific website’s resource.

and a URL (Uniform Resource Locator) is the unique address to access any resource in the world wide web. URLs have a well-defined structure and unique which was invented in RFC 1738 by Tim Berners-Lee, the inventor of the world wide web.

What is encoded URL?

URL encoding is a technique or mechanism for translating unprintable or special characters to a universally accepted format by web servers and browsers.

The most commonly encoded character in URL string is the character. We see this character whenever we see a plus-sign (+) in a URL which represents the space character. The plus sign acts as a special character representing that space in a URL.

What is decoded URL?

This is just the reverse process of encoding – translating back the URL to the readable english characters.

PowerShell Code to handle the URL encoding and decoding:

Add-Type -AssemblyName System.Web

$webURL="https://globalsharepoint.sharepoint.com/sites/TestSite/Shared Documents/"
Write-Host "The original url is " $webURL -ForegroundColor Green
#The below code is used to encode the URL
$urlToEncode = $webURL
$encodedURL = [System.Web.HttpUtility]::UrlEncode($urlToEncode) 
Write-Host "The encoded url is: " $encodedURL -ForegroundColor Green
#Encode URL code ends here

#The below code is used to decode the URL.
$urlTodDecode = $encodedURL
$decodedURL = [System.Web.HttpUtility]::UrlDecode($urlTodDecode)
Write-Host "The decoded url is: " $decodedURL -ForegroundColor Green
#Decode URL code ends here.

Test – Output:


Using online URL encoding and decoding:

There are many open web sites using which we can encode and decode the URL, the below URL is one among them.



Thus, in this post we have learned the below concepts:

  • How to a decode a string.
  • How to encode an URL using PowerShell.
  • How to decode an URL using PowerShell.
  • How to decode url in online.


See Also: