Connect-MsolService through Proxy in Powershell

Problem

I used to connect Azure AD Powershell module using Connect-MsolService command. I can always able to successfully connect via proxy server and without proxy. But for some reason, today, I am receiving the errors Exception of type Microsoft.Online.Administration.Automation.MicrosoftOnlineException’ was thrown and There was no endpoint listening at
https://provisioningapi.microsoftonline.com/provisioningwebservice.svc that could accept the message
 when I use Connect-MsolService command.


Error Message 1:

Connect-MsolService : There was no endpoint listening at 
https://provisioningapi.microsoftonline.com/provisioningwebservice.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 
At line:1 char:1 
+ Connect-MsolService -Credential $Livecred; 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo          : OperationStopped: (:) [Connect-MsolService], EndpointNotFoundException 
    + FullyQualifiedErrorId : System.ServiceModel.EndpointNotFoundException,Microsoft.Online.Administration.Automation 
   .ConnectMsolService

Error Message 2:

Connect-MsolService : Exception of type 'Microsoft.Online.Administration.Automation.MicrosoftOnlineException' was thrown. 
At line:1 char:1 
+ Connect-MsolService -Credential $Livecred; 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo          : OperationStopped: (:) [Connect-MsolService], MicrosoftOnlineException 
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.MicrosoftOnlineException,Microsoft.Online.Adm 
   inistration.Automation.ConnectMsolService 

Fix/Solution

The problem was solved for me after configuring Powershell to use proxy authentication for Microsoft Online endpoint (https://provisioningapi.microsoftonline.com/provisioningwebservice.svc) using Invoke-WebRequest command in Powershell.

Invoke-WebRequest -Proxy http://myporxyerver:myport -ProxyUseDefaultCredentials https://provisioningapi.microsoftonline.com/provisioningwebservice.svc

After running the above command, now the Powershell uses my proxy settings to connect Microsoft Office 365.

Note: replace myporxyerver with your proxy server and myport with your proxy server port.

Advertisement

4 thoughts on “Connect-MsolService through Proxy in Powershell”

Leave a Comment