我目前正忙于将 Azure AD PowerShell 脚本转换为 Microsoft Graph PowerShell。我已经有一些想要在 Azure 自动化中运行的脚本,但我尝试弄清楚如何连接到 Azure 自动化。
通过 Azure AD PowerShell,我在 Azure 自动化中拥有一个连接的服务帐户。通过 Microsoft Graph PowerShell,我尝试通过以下连接在 Azure 自动化帐户中使用 RunAs 帐户:
$Connection = Get-AutomationConnection -Name AzureRunAsConnection
# Get certificate from the automation account
$Certificate = Get-AutomationCertificate -Name AzureRunAsCertificate
# Connect to the Graph SDK endpoint using the automation account
Connect-MgGraph -ClientID $Connection.ApplicationId -TenantId $Connection.TenantId -CertificateThumbprint $Connection.CertificateThumbprint
当我运行 RunBook 创建连接时,出现错误:
Connect-MgGraph: C:\Temp\os4k24vd.4cs\xxxxxxxxxxxxxxxxxxx.ps1:5
Line | 5 | Connect-MgGraph -ClientID $Connection.ApplicationId -TenantId $Connec …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0,
| Culture=neutral, PublicKeyToken=xxxxxxx'. The system cannot | find the file specified.
我安装了 Connect-MgGraph
Microsoft.Graph.Authentication>> 运行时所需的以下模块:7.1 当我搜索时关于错误,它与 .NET 找不到 Json.NET 库有关。但是我在 Azure 自动化中缺少哪个模块,或者是否有其他方法将 Microsoft Graph PowerShell 与 Azure 自动化连接?
最佳答案
我希望您使用仅应用程序访问方法来连接 Azure 自动化。如果没有请引用MSDOC - App only Authentication
要获取证书和AppID,您可以使用以下命令
#To get App Id
$AppId = Get-AutomationVariable -Name '<Your AppID>'
# Get TenentId
$TenantId = Get-AutomationVariable -Name '< your tenantId>'
# Get Certificate
$CertificateName = Get-AutomationCertificate -Name '<Your Certificate>'
#Connect the mgGraph
Connect-MgGraph -ClientID $AppId -TenantId $TenantId -CertificateName $CertificateName ## Or -CertificateThumbprint
不过,您仍然遇到问题,请尝试一下 Automation Hybrid Runbook Worker以获得更大的灵 active 。
关于azure - Azure 自动化中的 Connect-MgGraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73350369/