How can I run an Azure powershell cmdlet through a proxy server with credentials?
Asked Answered
W

2

6

When I run the following Powershell cmdlet (from the Azure Management Tools Snapin):

get-osversions -subscriptionId **** -certificate (get-item cert:\CurrentUser\MY\******)

I get the following error message:

Get-OSVersions : The remote server returned an unexpected response: (407) Proxy Authenti cation Required. At line:1 char:15 + get-osversions <<<< -subscriptionId * -certificate (get-item cert:\CurrentUser\MY*****) + CategoryInfo : CloseError: (:) [Get-OSVersions], ProtocolException + FullyQualifiedErrorId : Microsoft.Samples.AzureManagementTools.PowerShell.HostedS ervices.GetOSVersionsCommand

Get-OSVersions : Object reference not set to an instance of an object. At line:1 char:15 + get-osversions <<<< -subscriptionId * -certificate (get-item cert:\CurrentUser\MY***) + CategoryInfo : CloseError: (:) [Get-OSVersions], NullReferenceException + FullyQualifiedErrorId : Microsoft.Samples.AzureManagementTools.PowerShell.HostedS ervices.GetOSVersionsCommand

It seems that the internet proxy server here is denying the script the access it requires.

I've had a good look around on the internet and it seems that there is no easy way around this problem since this cmdlet does not have a valid "-credentials" or proxy server parameter.

I know there is a 'Get-Credential' cmdlet but I don't think it helps. How would you pass the credential to the Azure cmdlet?

Can anyone think of any way to get around this issue?..

...other than using a different non-proxied internet connection?

I'm stumped.

Many Thanks for your time.

Wandy answered 25/7, 2011 at 15:42 Comment(0)
S
1

A few customers I know were successful using the method outlined here (Supporting Basic Auth proxies). If you need other proxy types, it follows the same pattern. The nice thing about this is it does not require changing the cmdlets.

Sternum answered 25/7, 2011 at 17:17 Comment(4)
Thanks for the tip. Apologies for the newbie question but how would you go about using this method with a powershell script?Wandy
You use the same method outlined, but I believe you would need to put the settings in the powershell.exe.configSternum
Thanks for the help! Created powershell.exe.config files in 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0' and 'C:\Windows\System32\WindowsPowerShell\v1.0' with the settings from the link. No longer getting the proxy error message.Wandy
It should be noted for completeness that I am now getting a new error with the powershell script but I think it's unrelated: Get-OSVersions : The type initializer for 'System.ServiceModel.DiagnosticUtility' threw an exception. At line:1 char:15 + get-osversions <<<< -subscriptionId ****** -certificate (get-item cert:\CurrentUser\MY *******) + CategoryInfo : CloseError: (:) [Get-OSVersions], TypeInitializationException + FullyQualifiedErrorId : Microsoft.Samples.AzureManagementTools.PowerShell.HostedServices.GetOSVersionsCommandWandy
W
18

Easier:

[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
Win answered 13/2, 2013 at 16:50 Comment(2)
I'll be honest and didn't run the accepted answer by dunnry, as this one looked so simple to try first. It works and it's easy to include in your PowerShell profile so it's automatically executed each time you run PowerShell.Pentamerous
Without this, a simple Get-AzureLocation failed, now it works great.Provolone
S
1

A few customers I know were successful using the method outlined here (Supporting Basic Auth proxies). If you need other proxy types, it follows the same pattern. The nice thing about this is it does not require changing the cmdlets.

Sternum answered 25/7, 2011 at 17:17 Comment(4)
Thanks for the tip. Apologies for the newbie question but how would you go about using this method with a powershell script?Wandy
You use the same method outlined, but I believe you would need to put the settings in the powershell.exe.configSternum
Thanks for the help! Created powershell.exe.config files in 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0' and 'C:\Windows\System32\WindowsPowerShell\v1.0' with the settings from the link. No longer getting the proxy error message.Wandy
It should be noted for completeness that I am now getting a new error with the powershell script but I think it's unrelated: Get-OSVersions : The type initializer for 'System.ServiceModel.DiagnosticUtility' threw an exception. At line:1 char:15 + get-osversions <<<< -subscriptionId ****** -certificate (get-item cert:\CurrentUser\MY *******) + CategoryInfo : CloseError: (:) [Get-OSVersions], TypeInitializationException + FullyQualifiedErrorId : Microsoft.Samples.AzureManagementTools.PowerShell.HostedServices.GetOSVersionsCommandWandy

© 2022 - 2024 — McMap. All rights reserved.