【问题标题】:Azure default subscription not found未找到 Azure 默认订阅
【发布时间】:2016-11-23 22:38:23
【问题描述】:

我一直在尝试创建一个 powershell 脚本来动态创建 Azuer 防火墙规则。

我使用的代码是:

$servername = "xxx" 
$username = "xx@xxx.onmicrosoft.com" 
$password = "xxx" 
$subscription = "Pay-As-You-Go" 
$secpasswd = ConvertTo-SecureString 
$password -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ($userName, $secpasswd) 

Login-AzureRmAccount -Credential $cred -SubscriptionName $subscription

Select-AzureSubscription -SubscriptionName $subscription -Default

$ipAddress = (Invoke-WebRequest 'http://myexternalip.com/raw').Content -replace "`n"

New-AzureSqlDatabaseServerFirewallRule -ServerName $servername -RuleName 'Test' -StartIpAddress $ipAddress -EndIpAddress $ipAddress

我还收到以下错误:

Select-AzureSubscription : 订阅名称 Pay-As-You-Go 不存在。

New-AzureSqlDatabaseServerFirewallRule :未指定默认订阅。使用 Select-AzureSubscription -Default 设置默认值 订阅。

我也尝试将 Login-AzureRmAccount 更改为 Add-AzureAccount,但没有任何区别。我创建的用户是 SQL 服务器的所有者。

还有什么我可能遗漏的吗?

【问题讨论】:

    标签: powershell azure


    【解决方案1】:

    看起来您正在混合使用 AzureRM 和 Azure 模式...您需要确保可以从该模式访问所需的订阅。如果您使用 Login-AzureRMAccount 或 Add-AzureRMAccount 登录 - 使用 Get-AzureRMSubscription 查看您有权访问的内容。

    如果您使用 Add-AzureAccount 登录,请使用 Get-AzureSubscription...

    检查一下,看看你发现了什么。

    【讨论】:

    • 对了。我现在添加了以下行:Get-AzureRMSubscription -SubscriptionName $subscription |我在 Google 上找到的 Set-AzureRmContext 但 New-AzureSqlDatabaseServerFirewallRule 仍然会引发错误,抱怨默认订阅。是否有 RM 等效项?
    • 找到它:New-AzureRmSqlServerFirewallRule。唯一的问题是它现在需要资源组名称,但这很容易提取。非常感谢
    猜你喜欢
    • 2017-02-07
    • 2018-01-26
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多