Adding Firewall rules with ip addresses for PAAS servers using Powershell

问题: I have Azure environment and I have to add firewall rule into all Pass servers for different subscriptions. Server name and Resource groups are different for all subscripti...

问题:

I have Azure environment and I have to add firewall rule into all Pass servers for different subscriptions. Server name and Resource groups are different for all subscriptions. For example: Enterprisedev Subscription.

Server              RESOURCE GROUP           SUBSCRIPTION
caddvsql11           DwDvRg01                Enterprise Dev/Test
caduasql11           DwUtRg01                Enterprise Dev/Test
cmspcsql01          CmsPcRg01                Enterprise Dev/Test
quomosql11          QuoMoRg11                Enterprise Dev/Test



Set-AzureRmContext  "Enterprisedev " 

new-AzureRmSqlServerFirewallRule -ResourceGroupName "DwDvRg01" -ServerName "caddvsql11" -FirewallRuleName "SAM_HOME" -StartIpAddress "22.7.180.91"
-EndIpAddress "22.7.180.91"

I am able to add ip address using this query for single server.But I need to add this firewall rule name and Ip address in all Paas servers in Azure, having different server and resource groups. Can some one Please help me in this.


回答1:

Set-AzureRmContext is the older version. There is a migration to the new Az cmdlets for Cloud Shell.

If all resource groups are under the same Subscription ID, then the script you used could be extended to include a firewall rule on the remaining three servers.

If they are all on individual subscriptions, you will need to include the cmdlet (Connect-AzAccount), followed by using the Set-AzContext cmdlet to change between subscriptions.

If you connect via the Cloud Shell session via the Azure Portal, you can use Set-AzContext to switch between subscription. The Connect-AzAccount cmdlet is needed if you are running from a desktop environment and need to authenitcate first.


回答2:

You can create a simple csv file with all the required inputs and then make use of Import-csv command.

Here is a quick sample csv and script.. You can add any other columns you need and make use of the values in appropriate commands.

enter image description here

foreach($rule in import-csv "E:firewallrules.csv") 
{ 
   Write-Host "Processing item with.. Server="$rule.Server "Resource Group ="$rule.ResourceGroup "Subscription="$rule.Subscription

   # Make use of variables like $rule.Server and so on in your commands here..
}
  • 发表于 2019-03-26 18:22
  • 阅读 ( 188 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除