使用AzurePowershell全局检查Azure SQL Server名称是否存在

时间:2017-02-26 17:15:56

标签: powershell azure azure-powershell

我正试图解决此错误消息

  

New-AzureRmSqlServer:45120:名称“server.database.windows.net”已存在。选择其他名称。

我可以检查资源组中是否存在SQL Server名称,但不确定如何全局检查。是的,我可以选择一个不同的名字 - 但如果它也存在,我会遇到同样的错误。

有没有办法通过'Try Catch'捕捉错误并做某事?提前感谢任何建议。

1 个答案:

答案 0 :(得分:1)

只需创建一个do while循环;)

do {
    $continue = $null
    New-AzureRmSqlServer ... -ErrorVariable continue -ErrorAction SilentlyContinue
    # Create another name here
} while ($continue)