Quick Tip: Using Azure PowerShell with Web Proxy and Fiddler
Does your organization use a web proxy server for securing outbound Internet access?
Do you use third-party tools, such as Fiddler, that rely on HTTP/HTTPS proxying?
If you’ve answered yes! to either of these questions, you’ll find that you’ll likely need to make a couple quick tweaks to your Azure PowerShell scripts for successful connectivity when communicating through a proxied connection.
In this article, I’ll provide 4 simple lines of code that you can add to the beginning of any Azure PowerShell scripts when you need to work with a proxy-based connection to the Microsoft Azure cloud.
Step 1 – Add Proxy URI to Script
Add the code below to the top of your Azure PowerShell script to define a proxy URI that your script can use for communicating with Microsoft Azure. Depending on your proxy scenario, the value you use for the $proxyString variable may be different in your environment. In the example below, I’m specifying the proxy URI value that’s commonly used with Fiddler.
$proxyString = "https://127.0.0.1:8888"
$proxyUri = new-object System.Uri($proxyString)
[System.Net.WebRequest]::DefaultWebProxy =
new-object System.Net.WebProxy ($proxyUri, $true)
Step 2 (Optional) – Add Proxy Credentials to Script
If the proxy configuration used in your environment requires authentication, you can also add one of the following lines to your script – depending on the type of authentication credentials required.
To use Windows credentials for proxy authentication, you can add …
[System.Net.WebRequest]::DefaultWebProxy.Credentials =
[System.Net.CredentialCache]::DefaultCredentials
Alternatively, to prompt for separate credentials that can be used for proxy authentication, you can add …
[System.Net.WebRequest]::DefaultWebProxy.Credentials =
Get-Credential
Done – Ready to test …
Once you’ve configured proxy-based connectivity using the steps above, you can test connectivity by attempting to authenticate to Microsoft Azure and retrieving a list of Azure subscriptions using the cmdlets below from Azure PowerShell v1.0.x:
Login-AzureRmAccount
Get-AzureRmSubscription