【问题标题】:How to Replace the AzureRM module with Az in Azure Automation Account如何在 Azure 自动化帐户中将 AzureRM 模块替换为 Az
【发布时间】:2020-03-07 23:30:16
【问题描述】:

我正在尝试使用 Azure 自动化帐户来运行一些作业,但我在安装 AzureRM 模块时遇到了困难。我手动安装了一些 Az 模块,但 PowerShell ISE 仍在使用 AzureRM,例如尝试在下面建立 RunAs 连接,

$RunAsConnection = Get-AutomationConnection -Name AzureRunAsConnection;try {$Login=Add-AzureRmAccount -ServicePrincipal
-TenantId $RunAsConnection.TenantId -ApplicationId $RunAsConnection.ApplicationId -CertificateThumbprint $RunAsConnection.CertificateThumbprint -ErrorAction Stop}catch{Sleep 10;$Login=Add-AzureRmAccount -ServicePrincipal -TenantId $RunAsConnection.TenantId -ApplicationId $RunAsConnection.ApplicationId -CertificateThumbprint $RunAsConnection.CertificateThumbprint};Set-AzureRmContext
-SubscriptionId $RunAsConnection.SubscriptionID

然后,我必须手动将其修改为下面的代码并且它可以工作。

$RunAsConnection = Get-AutomationConnection -Name AzureRunAsConnection;try {$Login=Add-AzureRmAccount -ServicePrincipal -TenantId $RunAsConnection.TenantId -ApplicationId $RunAsConnection.ApplicationId -CertificateThumbprint $RunAsConnection.CertificateThumbprint -ErrorAction Stop}catch{Sleep 10;$Login=Add-AzAccount -ServicePrincipal -TenantId $RunAsConnection.TenantId -ApplicationId $RunAsConnection.ApplicationId -CertificateThumbprint $RunAsConnection.CertificateThumbprint};Set-AzContext -SubscriptionId $RunAsConnection.SubscriptionID

如何解决这个问题以及如何强制自动化帐户使用 Az 而不是 Azure RM?

谢谢!

【问题讨论】:

标签: azure powershell azure-automation powershell-ise az


【解决方案1】:

import Az module之后,可以使用Connect-AzAccount进行认证,然后直接使用其他Az cmdlet。

一个例子是在自动化运行手册中使用Get-AzWebApp(需要导入Az.Websites 模块,如前所述)来获取Azure Web 应用程序详细信息:

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

#the cmdlet to get azure web app details
Get-AzWebApp -ResourceGroupName xxx

【讨论】:

    猜你喜欢
    • 2020-10-02
    • 2020-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 2018-11-04
    相关资源
    最近更新 更多