How to 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 parameter to some function.
#Parameter
$URL = "https%3A%2F%2Fcrescent.sharepoint.com%2Fsites%2Fmarketing%2F2018%2FDocuments%2FInfo%20Mgmt%20v2%2Epdf"

#Decode URL
[System.Web.HttpUtility]::UrlDecode($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)"
    }
}

#Parameter
$URL = "https%3A%2F%2Fcrescent.sharepoint.com%2Fsites%2Fmarketing%2F2018%2FShared%20Documents%2FInformation%20Management%20v2%2Epdf"

#Call the function to decode URL
Decode-URL $URL 
How to Decode a SharePoint Online URL using PowerShell? How to Decode a SharePoint Online URL using PowerShell? Reviewed by Salaudeen Rajack on March 05, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.