【问题标题】:Getting error when calling Powershell script Get-AzureRmSqlServerFirewallRules?调用 Powershell 脚本 Get-AzureRmSqlServerFirewallRules 时出错?
【发布时间】:2021-08-03 08:04:44
【问题描述】:

我正在调用以下脚本

az login -u <USERNAME> -p <PWD> 
az account set --subscription Sub2
$sourceResourceGroup='Source-Networking'
$sourceSqlServerName='SourceSQLServer'
$sourceFirewallRules = Get-AzureRmSqlServerFirewallRule -ResourceGroupName 
  $sourceResourceGroup -ServerName $sourceSqlServerName

资源组“Source-Networking”位于订阅 Sub2 中,但我收到错误资源组“Source-Networking”找不到。 我以管理员身份使用 Windows Powershell ISE 来运行该命令。 如果我在 Microsoft 网站上使用在线 Azure Cloud Shell 并显示“试试看”,它似乎可以工作。

ISE PowerShell 窗口中可能有什么问题?

【问题讨论】:

  • 确保脚本中使用的 至少对 RG 具有读取权限。还要确保 RG 名称正确(包括大小写)。
  • 我已经检查了所有这些,这很好。我想知道是否需要转义资源组名称中的“-”,因为它可能会导致 powershelll 出现问题?

标签: powershell azure-cli powershell-ise


【解决方案1】:

在上面的共享脚本中,您似乎正在尝试使用 AzureCLI 和 AzureRM 模块的组合运行脚本,其中这些脚本将在 ISE PowerShell 窗口中失败。

  • 如果要使用 AzureCLI 获取 Sql server 防火墙规则,可以参考以下脚本
az login 
az account set --subscription '<<subscriptionId>>'
GroupName='resource-group-name'
ServerName='sql-server-name'
az sql server firewall-rule show --name firewall --resource-group $GroupName --server $ServerName
  • 如果你想获取Sql server,可以参考下面的脚本 使用 ISE PowerShell 和 AzureRM 模块的防火墙规则
Connect-AzureRmAccount
Set-AzureRmContext -Subscription '<<subscriptionId>>'
$groupname = 'resource-group-name'
$serverName = 'sql-server-name'
$firewallrule = Get-AzureRmSqlServerFirewallRule -ResourceGroupName $group -ServerName $servername

【讨论】:

    猜你喜欢
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 2019-12-08
    相关资源
    最近更新 更多