试图删除azure中的sql db时出现错误“;未指定默认订阅";

试图删除azure中的sql db时出现错误“;未指定默认订阅";,azure,powershell,azure-powershell,Azure,Powershell,Azure Powershell,我目前正在尝试编写一个powershell脚本,该脚本登录azure,然后删除一个SQL数据库。 当它到达数据库删除时,它给出一个错误: Remove-AzureSqlDatabase : No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to set the default subscription. 我对问题所在感到困惑,并

我目前正在尝试编写一个powershell脚本,该脚本登录azure,然后删除一个SQL数据库。 当它到达数据库删除时,它给出一个错误:

Remove-AzureSqlDatabase : No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to set the default 
subscription.
我对问题所在感到困惑,并尝试通过
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"

您不能将三个powershell模块
Azure
Az
AzureRm
混合在一起,如果您已经安装了该模块,我建议您卸载
AzureRm
模块,该模块已弃用,将永远不会更新

要使用
Az
模块删除sql db,脚本如下所示。确保您的帐户具有订阅/SQL Server的RBAC角色(例如,
所有者
参与者

$passwd = ConvertTo-SecureString password -AsPlainText -Force
$pscredential = New-Object System.Management.Automation.PSCredential('accountname', $passwd)
Connect-AzAccount -Credential $pscredential -Tenant "<tenant-id>" 
Set-AzContext -Subscription "<subscription-id>"
Remove-AzSqlDatabase -ResourceGroupName "<ResourceGroupName>" -ServerName "<ServerName>" -DatabaseName "<DatabaseName>"
$passwd=converttosecurestring密码-AsPlainText-Force
$pscredential=新对象System.Management.Automation.pscredential('accountname',$passwd)
连接AzaAccount-凭据$pscredential-租户“”
设置上下文-订阅“”
删除AZSQLDABASE-ResourceGroupName“”-ServerName“”-DatabaseName“”

您是否尝试过将名称用引号括起来?或者改为通过
-SubscriptionId
尝试?
$passwd = ConvertTo-SecureString password -AsPlainText -Force
$pscredential = New-Object System.Management.Automation.PSCredential('accountname', $passwd)
Connect-AzAccount -Credential $pscredential -Tenant "<tenant-id>" 
Set-AzContext -Subscription "<subscription-id>"
Remove-AzSqlDatabase -ResourceGroupName "<ResourceGroupName>" -ServerName "<ServerName>" -DatabaseName "<DatabaseName>"