Virtual Geek

Tales from real IT system administrators world and non-production environment

PowerShell Encode or Decode an WebURL

While working few web scrapping project, I was able to get the table data, but few of the data had few special characters in the table, which was in http encoded format. Related article is a Powershell web scrapping extract table from html. The encoded http data was not readable. This data can be encode or decode using PowerShell scripts easily. When you use special characters on html page, that character need to be converted/encoded. To read back it need to decoded.

Powershell has System.Web .net assembly need to be loaded in order to use the related commands. I have a test url with spaces, which I need to put inside the HTML report, it is not in the correct format when using inside HTML code page. 

Add-Type -AssemblyName System.Web

$date = (Get-Date).AddDays(-7).DateTime

$url = "$date"
$url August 2021 14:38:49

microsoft powershell add-type -assemblyname system.web get-date adddays datetime encode url decode url using powershell encrypt decrypt.png

Related Articles:
Create an interactive HTML report with PowerShell data
PowerShell convert string to base64 value

To encode the data to be used on http webpage with special characters use below code with System.web.HttpUtility .net object. Method I am using is UrlEncode().

#Encode Url
$encodedUrl = [System.Web.HttpUtility]::UrlEncode($url$encodedUrl

Microsoft Powershell encode decode weburl url system.web.httpUtility urlencode get-time urldecode automation ps1 minister website uniform resource locater.png

To decode the collected data from http web-scrapping back to readable format, use below code with method UrlDecode().

#Decode Url
$decodedUrl = [System.Web.HttpUtility]::UrlDecode($encodedUrl)
$decodedUrl August 2021 14:38:49

Download this script here or it is also available on

Useful Articles
Powershell Convert range of numbers into another list of numbers maintaining ratio
Powershell Active Directory: List complete hierarchy of upstream nested groups recursively of User
Powershell Active Directory: Show treeview of User or Group memberof hierarchy
Powershell Active Directory: Show treeview of nested Group members downstream hierarchy
Oneliner Microsoft Powershell Script Get members from a list of group from Active Directory in excel
Powershell Active Directory 1: Check, enable and disable child OU protect object from accidental deletion
Oneliner Powershell how to add or remove AD user members and objects in groups

Go Back


Blog Search

Page Views


Follow me on Blogarama