![](/img/trans.png)
[英]Setting Api version in Azure automation account using powershell
[英]Azure Automation account Powershell Error setting context
我正在嘗試使用 Azure 自動化帳戶運行一個簡單的 Powershell Runbook。 我有一個 RunasAccount 設置,它對訂閱具有貢獻者特權,我正在嘗試獲取在我的一個 Sql 服務器中列入白名單的 IP 列表。
Import-Module Az.Sql
Import-Module Az.Accounts
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
Get-AzSqlServerFirewallRule -ResourceGroupName test-rg -ServerName test-server101
當我運行它時,我收到以下錯誤。
Get-AzSqlServerFirewallRule :在上下文中找不到訂閱。 請確保您提供的憑據有權訪問 Azure 訂閱,然后運行 Connect-AzAccount 進行登錄。 在 line:36 char:1 + Get-AzSqlServerFirewallRule -ResourceGroupName test-rg -ServerName te ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzSqlServerFirewallRule], AzPSApplicationException +fullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.FirewallRule.Cmdlet.GetAzureSqlServerFirewallRule
我注意到 Get-AzSqlServerFirewallRule commandlet 有一個選項來設置 -DefaultProfile。 但是我不確定這里要給出什么。
我在這里做錯了什么?
您正在混合 PowerShell 模塊。 如果使用 Az 模塊,則需要使用Connect-AzAccount
而不是Add-AzureRmAccount
。 如果使用 AzureRm 模塊,則需要使用Get-AzureRmSqlServerFirewallRule
而不是Get-AzSqlServerFirewallRule
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.