Powershell 工作流运行手册 - 身份验证失败

Powershell Workflow runbook - authentication failed

我在 Azure 门户的 runbook 上有一个 Azure Automation Run As account. When I run the following code (from step 5 的 Azure 在线教程),我收到如下所示的错误。 问题:我在这里可能遗漏了什么,我们如何解决这个问题?

操作手册代码:

# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave –Scope Process

$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID `
-ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

$AzureContext = Select-AzSubscription -SubscriptionId $Conn.SubscriptionID

错误:

Failed At line:4 char:1
+ Disable-AzContextAutosave –Scope Process
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cannot find the 'Disable-AzContextAutosave' command. If this command is defined as a workflow, ensure it is defined before the workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on this system), place it in an InlineScript: 'InlineScript { Disable-AzContextAutosave }'

我假设您还没有将 Az.Accounts 模块导入到您的自动化帐户中。 Disable-AzContextAutosaveConnect-AzAccountSelect-AzSubscription 来自该模块。

按照此指南前往 Import Az modules