我当前正在尝试编写一个Powershell脚本,该脚本登录到Azure中,然后删除一个SQL数据库。 在删除数据库时,会出现错误:
Remove-AzureSqlDatabase : No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to set the default
subscription.
当我尝试使用Select-AzureSubscription -Default -SubscriptionName Pay-As-You-Go
添加默认订阅时,我也会收到错误消息:
Select-AzureSubscription : The subscription name Pay-As-You-Go doesn't exist.
对于问题所在,我感到困惑,并且还尝试通过connect-AzAccount
连接到该帐户。
完整的脚本是:
$passwd = ConvertTo-SecureString password -AsPlainText -Force
$pscredential = New-Object System.Management.Automation.PSCredential('accountname', $passwd)
Connect-AzureRmAccount -Credential $pscredential -Tenant "tenant string"
# Set-AzContext -SubscriptionId "subscription id"
Select-AzureSubscription -Default -SubscriptionName Pay-As-You-Go
# Get-AzureSubscription -SubscriptionName “Pay-As-You-Go” | Select-AzureSubscription -Default
Remove-AzureSqlDatabase -ServerName migrate -DatabaseName "AWS-Copy"
答案 0 :(得分:0)
您不能将三个Powershell模块Azure
,Az
,AzureRm
混合在一起,并且,如果您已经安装了Az
模块,建议您卸载{ {1}}模块,它已被弃用,永远不会更新。
要使用AzureRm
模块删除sql db,您的脚本应如下所示。确保您的帐户具有订阅/ SQL Server的RBAC角色(例如Az
,Owner
)。
Contributor