Reputation: 57
I would like to run a Azure Automation Runbook (PowerShell) and run connect-PnPOnline or connect-MicrosoftExchange
clientid & clientsecret will be deprecating User is MFA enabled
Can't I connect trough managed identity or keyvault or something else? Who can point me in the right direction?
Upvotes: 0
Views: 545
Reputation: 7898
Run connect-PnPOnline or connect-MicrosoftExchange trough managed identity:
I tried authenticating to the required conections using Azure PowerShell as well as Azure Automation runbook as follow:
SystemAssigned Managed Identity:
Connect-PnPOnline -Url "https://microsoftapc.sharepoint.com/teams/<Site_Name>"-ManagedIdentity
UserAssigned Managed Identity:
Connect-PnPOnline -Url ""-ManagedIdentity -UserAssignedManagedIdentityObjectId <ObjectId of UserAssigned Managed Identity>
Client_ID & Client_secret:
Install-Module -Name PnP.PowerShell
connect-pnponline -url "https://microsoftapc.sharepoint.com/teams/<Site_Name>"-ClientId "48b4f657-904f-496d-b02a-49cc492b3ee3" -ClientSecret "Tis8Q~Pxn3F2t8kllVCV5pCC2u2SMkxcSEeOrds2" -WarningAction Ignore
Output(AZ Powershell):
Azure runbook:
First of all, Add the required modules by going to Automation Account -> Shared Resources -> Modules -> Add a Module
To check whether modules are successfully imported, Give
Install-Module -Name ExchangeOnlineManagement -Scope AllUsers
Get-command -Module ExchangeOnlineManagement
Azure PowerShell:
Connect-ExchangeOnline -ManagedIdentity -Organization "xxxxx" -ManagedIdentityAccountId "<UserManagedIdentityID>"
References:
Check here for other possible ways to Connect-PnPOnline & connect-ExchangeOnline.
Upvotes: 2