azure - Azure 自动化中的 Connect-MgGraph

标签 azure powershell automation

我目前正忙于将 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/

相关文章:

javascript - 在 JavaScript 中的 Application Insights 中卸载之前保存事件

javascript - Application Insight 中的 JS 异常

c# - PowerShell 与 MongoDB C# 驱动程序的方法不兼容?

c# - 向文件添加新的元数据属性

java - 在虚拟机内自动移动鼠标,独立于真实鼠标

c# - 以编程方式点击网页

c# - 为什么 Azure 表存储在使用 ResolveName 时不保留类型名称?

Azure 函数访问存储帐户且系统分配的标识失败

powershell - 客户端永远等待远程服务器返回网页

git - 是否可以创建跟踪不存在的远程分支