Converting VBScript's Unescape Function

Definition: Decodes a string encoded with the Escape function.

Unescape

Suppose someone hands you a string value like this one, a value that has been encoded using the VBScript Escape function (or its equivalent):

http%3a%2f%2fwww.microsoft.com%2ftechnet%2fscriptcenter%2fdefault.mspx

Can you use Windows PowerShell to decode this value (that is, turn it back into a regular string value)? You can if you use the .Net Framework’s System.Web.HTTPUtility class and the URLDecode() method. Assuming that the string value is stored in the variable $a these two commands should do the trick:

[Reflection.Assembly]::LoadWithPartialName("System.Web")
$a = [web.httputility]::urldecode($a)

When you run the commands and then echo back the value of $a you should get the following:

https://www.microsoft.com/technet/scriptcenter/default.mspx

Return to the VBScript to Windows PowerShell home page