问题:
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.
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..
}