Last week, firewall support was added to Azure Analysis Service (https://azure.microsoft.com/en-us/blog/azure-analysis-services-adds-firewall-support/). The thing is that, at the time of writing, there is no AzureRM cmdlet available to Use PowerShell to Enable Azure Analysis Services Firewall

So, with the help of Resource Explorer I found which properties must be added to the service (resource) in order to enable the firewall:

  • ipV4FirewallSettings.firewallRules
  • ipV4FirewallSettings.enablePowerBIService

The following scripts use the Set-AzureRmResource cmdlet to set those properties.

 1Param 
 2(
 3    [Parameter(Mandatory = $true)][string]$resourceGroupName,
 4    [Parameter(Mandatory = $true)][string]$analysisServicesName,
 5    [Parameter(Mandatory = $true)][string]$firewallRuleName,
 6    [Parameter(Mandatory = $true)][string]$rangeStart,
 7    [Parameter(Mandatory = $true)][string]$rangeEnd)
 8
 9function Add-AnalysisServicesFirewallRule($props, $firewallRuleName, $rangeStart, $rangeEnd) {
10    # Check if the rule exists
11    $existingRules = $props.ipV4FirewallSettings.firewallRules | `
12        Where-Object {$_.firewallRuleName -eq $firewallRuleName}
13
14    # Add the rule if needed
15    if ($existingRules -eq $null) {
16        # Create the rule object
17        $ruleProperties = [ordered]@{
18            "firewallRuleName" = $firewallRuleName;
19            "rangeStart"       = $rangeStart;
20            "rangeEnd"         = $rangeEnd;
21        }
22        $rule = New-Object -TypeName PSObject
23        $rule | Add-Member -NotePropertyMembers $ruleProperties
24
25        # Add the rule 
26        $rules = [System.Collections.ArrayList]$props.ipV4FirewallSettings.firewallRules
27        $index = $rules.Add($rule)
28        $props.ipV4FirewallSettings.firewallRules = $rules
29    }
30}
31
32function Add-FirewallSectionAndEnablePowerBIAccess($props) {
33    # Check if ipV4FirewallSettings property exists
34    $ipV4FirewallSettingsProperty = $props | Get-Member -Name "ipV4FirewallSettings"
35    if (!$ipV4FirewallSettingsProperty) {
36        # Create the ipV4FirewallSettings property and enable the PowerBI Service
37        $props | Add-Member @{ipV4FirewallSettings = [ordered] @{ 
38                "firewallRules"        = @()
39                "enablePowerBIService" = $true
40            }
41        }
42    }
43}
44
45# Get the AnalysisServices resource properties
46$resource = Get-AzureRmResource `
47    -ResourceGroupName $resourceGroupName `
48    -ResourceType "Microsoft.AnalysisServices/servers" `
49    -ResourceName $analysisServicesName
50
51$props = $resource.Properties
52
53Add-FirewallSectionAndEnablePowerBIAccess $props
54
55Add-AnalysisServicesFirewallRule $props $firewallRuleName $rangeStart $rangeEnd
56
57Set-AzureRmResource `
58    -PropertyObject $props `
59    -ResourceGroupName $resourceGroupName `
60    -ResourceType "Microsoft.AnalysisServices/servers" `
61    -ResourceName $analysisServicesName `
62    -Force

If you save the script in a file (i.e Add-AzureRmAnalysisServicesFirewallRule.ps1) you can run it as follows:

1.\Add-AzureRmAnalysisServicesFirewallRule.ps1

The script will ask you for:

  • The resource group name where the Analysis Service is deployed
  • The Analysis Service Name
  • The firewall rule name
  • The starting ip
  • The end ip

Get the code here or download the file from the Technet Gallery.

Hope it helps!