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.
Decode SharePoint Online URL using PowerShell:
We can also use SharePoint Online method:
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.
#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 $URLIn another situation, I had to calculate the length of the encoded URL in SharePoint and achieved it with:
$URL = "https://crescent.sharepoint.com/personal/salaudeen_crescent_com/Shared Documents/Assets & Inventory.xlsx" Write-host([URI]::EscapeUriString($URL))To decode SharePoint URLs, you can also use Online tools like:
No comments:
Please Login and comment to get your questions answered!