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 and also we will learn how to decode a SharePoint list id (GUID) using the online tool.

Introduction:

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 on 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 the 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 that represents the space character. The plus sign acts as a special character representing that space in a URL.

 

 

What is the 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:

cls
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:

URLEncodingDecoding

 

 

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.

https://urldecode.org/

Using Online tool decodes a SharePoint List ID (GUID)

This is a great little but a very helpful tool by Eric Meyer. Input a nasty looking URL string, and it will make it into something that you can read.

If we go to the list edit page, we will get the below nasty URL which is very unformatted and difficult to understand,

Original URL: /_layouts/listedit.aspx?List= %7BAA90DD8B%2DD2B7%2D49E9%2DA8DE%2D9138AB94CA68%7D

If we decode the above URL using this tool, we will get the below friendlier URL.

Decoded URL: /_layouts/listedit.aspx?List ={AA90DD8B-D2B7-49E9-A8DE-9138AB94CA68}

Example:

Tool URL: https://meyerweb.com/eric/tools/dencoder/

Decode SharePoint List ID (GUID) - URL Decoder/Encoder
Decode SharePoint List ID (GUID) – URL Decoder/Encoder

Source:

 

 

Summary:

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

  • How to decode a string.
  • How to encode a URL using PowerShell.
  • How to decode a URL using PowerShell.
  • How to decode URL in online.
  • How to decode a SharePoint list ID (GUID) online.

References:

 

See Also:

 

Free download SharePoint Online & Office 365 Administration eBook(238 Pages)

Get the PDF eBook from here:




 

 
FREE DOWNLOAD

Send download link to:

Subscribe to get exclusive content and recommendations every month. You can unsubscribe anytime.