首页 > 解决方案 > Powershell 工作流运行手册 - 身份验证失败

问题描述

我有一个Azure 自动化 Run As account。当我在 Azure 门户中的 Runbook 上运行以下代码(来自 Azure 在线教程的第 5 步)时,我收到如下所示的错误。问题:我可能在这里遗漏了什么,我们如何解决这个问题?

运行手册代码

# 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 }'

标签: azureazure-powershellazure-automationazure-runbook

解决方案


我假设您没有将Az.Accounts模块导入您的自动化帐户。Disable-AzContextAutosaveConnect-AzAccount并且Select-AzSubscription来自这个模块。

按照本指南导入 Az 模块


推荐阅读