Could not find type [System.Web.HttpUtility] in PowerShell

I'm trying to get the access token for a Microsoft Translator application using PowerShell, but some process commands fail as a result of the error:

Unable to find type [System.Web.HttpUtility] 

At first I typed the code, but the same error shows if I copy the code directly from the MSDN page to PowerShell ISE (and replace the missing values):

 # ... $ClientID = '<Your Value Here From Registered Application>' $client_Secret = '<Your Registered Application client_secret>' # If ClientId or Client_Secret has special characters, UrlEncode before sending request $clientIDEncoded = [System.Web.HttpUtility]::UrlEncode($ClientID) $client_SecretEncoded = [System.Web.HttpUtility]::UrlEncode($client_Secret) # ... 

I am new to PowerShell (I usually use Linux for development), but I assumed that this should work ready without the need to install additional tools; if not, where can I find them?

+5
source share
1 answer

You need to download the System.Web assembly. Use the Add-Type cmdlet, for example,

 PS C:\> [System.Web.HttpUtility]::UrlEncode("www.google.com") Unable to find type [System.Web.HttpUtility]. PS C:\> Add-Type -AssemblyName System.Web PS C:\> [System.Web.HttpUtility]::UrlEncode("www.google.com") www.google.com 
+17
source

All Articles