Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, January 24, 2019 4:55 PM
Hi Everyone,
I am trying to connect to the O365 environment using MSonline from Azure Automation Runbook.
I just have these two lines in my Runbook -
$credObject = Get-AutomationPSCredential -Name "MSOnline-Credentials"
Connect-MsolService -Credential $credObject
The MSOnline-Credentials credential is a AD Admin credential that has Admin access to the O365 environment. I am able to connect from my PowerShell with exact same credentials.
However, when I try to run the job, I am getting below error
Connect-MsolService : An error occurred while sending the request.
At line:2 char:1
+ Connect-MsolService -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Connect-MsolService], HttpRequestException
+ FullyQualifiedErrorId :
System.Net.Http.HttpRequestException,Microsoft.Online.Administration.Automation.ConnectMsolService
I am unable to find details about what went wrong with the HTTP request. Looking for any guidance regarding this.
Do we require any special actions on O365 side to allow the request from Azure Automation etc? The credentials I have used are created in the automation account directly and not Run As Credentials. Does this make any difference? From the error, it doesnt seem to be a credential issue. Please guide.
Thanks,
Partha
All replies (8)
Friday, January 25, 2019 5:14 AM
Hello ParthaKS, If I understand correctly, the 2 line cmd works locally but fails once uploaded to the Azure Automation account. Perhaps you need to install the MS Online Module on the Automation account.
Go here for more information on updating modules in Azure Automation.
Friday, January 25, 2019 5:19 AM
Hi Femisulu,
Thanks for the response. I have installed the Module in the automation account. When the module is not installed, we get the error connect-Msolservice is not recognized commandlet. It cannot be HTTP error if the module was not loaded properly.
Thanks,
Partha
Friday, January 25, 2019 5:22 AM
Agreed. Just wanted to confirm. Will investigate this a bit more and get back to you. thanks for your patience.
Friday, January 25, 2019 5:27 AM
Just FYI, there is a second option to connect to O356. Curious if you've tried this.
Friday, January 25, 2019 6:04 AM
just tried the second option now and I get Auth error
+ CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], HttpRequestException
+ FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Again I can connect from PowerShell on my local machine.
Do you need to be Global Admin to connect from Azure to O365?
Saturday, January 26, 2019 2:21 AM
Interesting....
Latest update:
Worked internally to test this and we were able to successfully connect with the sample cmd (below) from Azure and Hybrid Worker (On-Prem). Can you retry using the sample below?
$cred = Get-AutomationPSCredential -Name "cred"
Connect-MsolService -Credential $cred
Get-MsolCompanyInformation
Monday, January 28, 2019 7:44 AM
I am using Free Trail subscription for this test. Could this be an issue. It is free trail using my corporate credentials.
Thursday, March 12, 2020 2:41 PM
$cred = Get-AutomationPSCredential -Name "cred"
Connect-MsolService -Credential $cred
to connect to MSOLservice what type of credential we need to use ?
i tried with O365 user to connect to MSOLservice and it worked but when i tried to connect using Service principal of Automation account to run the jobs in runbooks i am getting error
Can you please confirm if we can use the Service principal of Automation account to connect to MSOL Service and check the password policy ?
Thanks,
neela