[英]Azure Automation account Powershell Error setting context
I am trying to run a simple powershell runbook using Azure automation account.我正在尝试使用 Azure 自动化帐户运行一个简单的 Powershell Runbook。 I have a RunasAccount setup which has contributor previlege over the subscription and I am trying to get a list of IP's whitelisted in one of my Sql server.我有一个 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
While I run this I get the below error.当我运行它时,我收到以下错误。
Get-AzSqlServerFirewallRule : No subscription found in the context. Get-AzSqlServerFirewallRule :在上下文中找不到订阅。 Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Connect-AzAccount to login.请确保您提供的凭据有权访问 Azure 订阅,然后运行 Connect-AzAccount 进行登录。 At line:36 char:1 + Get-AzSqlServerFirewallRule -ResourceGroupName test-rg -ServerName te ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzSqlServerFirewallRule], AzPSApplicationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.FirewallRule.Cmdlet.GetAzureSqlServerFirewallRule在 line:36 char:1 + Get-AzSqlServerFirewallRule -ResourceGroupName test-rg -ServerName te ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzSqlServerFirewallRule], AzPSApplicationException +fullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.FirewallRule.Cmdlet.GetAzureSqlServerFirewallRule
I noticed that the Get-AzSqlServerFirewallRule commandlet has an option to set -DefaultProfile.我注意到 Get-AzSqlServerFirewallRule commandlet 有一个选项来设置 -DefaultProfile。 However I am not sure what is to be given here.但是我不确定这里要给出什么。
What am I doing wrong here?我在这里做错了什么?
You're mixing PowerShell modules.您正在混合 PowerShell 模块。 If you're using the Az module, then you need to use Connect-AzAccount
rather than Add-AzureRmAccount
.如果使用 Az 模块,则需要使用Connect-AzAccount
而不是Add-AzureRmAccount
。 If you're using the AzureRm module, then you need to use Get-AzureRmSqlServerFirewallRule
rather than Get-AzSqlServerFirewallRule
.如果使用 AzureRm 模块,则需要使用Get-AzureRmSqlServerFirewallRule
而不是Get-AzSqlServerFirewallRule
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.