Using Azure PowerShell with Web Proxy
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 = "http://127.0.0.1:8888"
$proxyUri = new-object System.Uri($proxyString)
[System.Net.WebRequest]::DefaultWebProxy =
new-object System.Net.WebProxy ($proxyUri, $true)
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
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
Comments