Azure自动化中的连接管理图

ssgvzors  于 2022-11-17  发布在  其他
关注(0)|答案(2)|浏览(179)

我当前正忙碌将我的Azure AD PowerShell脚本转换为Microsoft Graph PowerShell。我已经有一些要在Azure自动化中运行的脚本,但我尝试找出如何连接到Azure自动化。
通过Azure AD PowerShell,我在Azure自动化中有一个连接的服务帐户。通过Microsoft Graph PowerShell,我正在尝试使用Azure自动化帐户中的运行方式帐户,该帐户具有以下连接:

$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-MgGraphMicrosoft.Graph.Authentication〉〉运行时所需的以下模块:7.1当我搜索错误时,发现.NET找不到Json.NET库。但我在Azure自动化中缺少哪个模块,或者是否有其他方法将Microsoft Graph PowerShell与Azure自动化连接?

1tuwyuhd

1tuwyuhd1#

我希望您使用仅限应用程序访问方法连接Azure自动化。如果不是,请参阅MSDOC - App only Authentication
要获取证书AppID,您可以使用以下命令let

#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以获得更大的灵活性。

lmyy7pcs

lmyy7pcs2#

问题不出在第一个连接脚本上,而是运行时版本。在更改为PS 5. 1而不是7. 1后,一切都正常。Runbook现在显示“欢迎欢迎使用Microsoft Graph!”

$Connection = Get-AutomationConnection -Name AzureRunAsConnection

# Connect to the Graph SDK endpoint using the automation account
Connect-MgGraph -ClientID $Connection.ApplicationId -TenantId $Connection.TenantId -CertificateThumbprint $Connection.CertificateThumbprint

相关问题