简体   繁体   English

Azure 自动化帐户 Powershell 错误设置上下文

[英]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.

相关问题 使用 powershell 在 Azure 自动化帐户中设置 Api 版本 - Setting Api version in Azure automation account using powershell 通过PowerShell创建Azure自动化连接-错误“未找到帐户” - Creation of an Azure Automation Connection via PowerShell - error 'account was not found' 从 Azure 自动化帐户 Powershell 上传数据 - Upload data from Azure Automation Account Powershell Azure 自动化帐户中的绑定重定向 PowerShell Runbook - Binding Redirection in Azure Automation Account PowerShell Runbook Powershell PSPKI 模块在 azure 自动化帐户中不起作用 - Powershell PSPKI module is not working in azure automation account 使用 PowerShell 获取 Azure 自动化帐户连接的服务主体 - Getting the service principal for an Azure Automation Account connection using PowerShell 如何在 azure 自动化账户中自动导入 Az Powershell 模块? - How to import automatically Az Powershell modules in azure automation account? 如何在 PowerShell 运行手册中使用 Azure 自动化帐户“加密变量”? - How to use Azure Automation Account 'Encrypted Variables' in PowerShell runbook? 带有证书的Azure自动化中的身份验证错误 - Powershell代码 - Authentication error in Azure Automation with certificates - Powershell code Azure 自动化 Powershell - Azure Automation Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM