How to Encode-Decode a SharePoint Online URL using PowerShell?

Requirement: Decode a URL in SharePoint Online

PowerShell to Decode URL:
We need decoded URLs in various scenarios in SharePoint. Say, we want to pass the file URL as a parameter to some function.
$URL = ""

#Decode URL

Decode SharePoint Online URL using PowerShell:
We can also use SharePoint Online method: 
#Import PoweShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

#Function to Decode URL
Function Decode-URL([string]$URL)
    Try {
        #Decode the URL
        Return [Microsoft.SharePoint.Client.Utilities.HttpUtility]::UrlKeyValueDecode($URL)
    catch {
        Return "Error Getting De-codedURL: $($_.Exception.Message)"

$URL = ""

#Call the function to decode URL
Decode-URL $URL 
In another situation, I had to calculate the length of the encoded URL in SharePoint and achieved it with:
$URL = " Documents/Assets & Inventory.xlsx"
To decode SharePoint URLs, you can also use Online tools like:
sharepoint url decode online

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.