可以使用cmdlet将azure自动化帐户连接到azuread:
没有使用存储在自动化帐户中的凭据吗?
我正在使用带有证书的以下代码,并且工作正常:
$azureadcred = Get-AutomationPSCredential -Name 'AzureAD'
Connect-AzureAD -credential $azureadcred
$o365cred = Get-AutomationPSCredential -Name 'O365'
Connect-Msolservice -credential $o365cred
感谢您的帮助
谢谢
答案 0 :(得分:0)
如何在没有用户的情况下连接AzureAD模块
我们可以使用服务主体来连接模块AzureAD。同时,您使用Azure自动化帐户,我们可以直接使用Azure Automation Run As accounts连接该模块。
详细步骤如下。
将Azure AD role分配给运行方式帐户。 一种。获取运行方式帐户的对象ID
b。分配角色
Connect-AzureAD
$role =Get-AzureADDirectoryRole -Filter "DisplayName eq 'Company Administrator'"
Add-AzureADDirectoryRoleMember -ObjectId $role.ObjectId -RefObjectId <the object id you copy>
$servicePrincipalConnection=Get-AutomationConnection -Name 'AzureRunAsConnection'
$connectState = Connect-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
if ($connectState) {
"Connected."
} else {
"Doesn't seem to be connected."
}
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
$context.Account
$graphToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, "https://graph.microsoft.com").AccessToken
$aadToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, "https://graph.windows.net").AccessToken
Connect-AzureAD -TenantId $context.tenant.id -AccountId $context.Account.Id -AzureEnvironmentName $context.Environment.Name -AadAccessToken $aadToken -MsAccessToken $graphToken
get-azureaduser -Top 5