Update the RDP port range values

This sample script changes the RDP port range values on the cluster node VMs after the cluster has been deployed. Azure PowerShell is used so that the underlying VMs do not cycle. The script gets the Microsoft.Network/loadBalancers resource in the cluster's resource group and updates the inboundNatPools.frontendPortRangeStart and inboundNatPools.frontendPortRangeEnd values. Customize the parameters as needed.


This article has been updated to use the Azure Az PowerShell module. The Az PowerShell module is the recommended PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

If needed, install the Azure PowerShell using the instruction found in the Azure PowerShell guide.

Sample script

Set-AzContext -SubscriptionId 'yourSubscriptionId'

$groupname = "mysfclustergroup"

# Get the load balancer resource
$resource = Get-AzResource | Where {$_.ResourceGroupName –eq $groupname -and $_.ResourceType -eq "Microsoft.Network/loadBalancers"} 
$lb = Get-AzResource -ResourceGroupName $groupname -ResourceType Microsoft.Network/loadBalancers -ResourceName $resource.Name

# Update the front end port range
$lb.Properties.inboundNatPools.properties.frontendPortRangeStart = $start
$lb.Properties.inboundNatPools.properties.frontendPortRangeEnd = $end

# Write the inbound NAT pools properties
Write-Host ($lb.Properties.inboundNatPools | Format-List | Out-String)

# Update the load balancer
Set-AzResource -PropertyObject $lb.Properties -ResourceGroupName $groupname -ResourceType Microsoft.Network/loadBalancers -ResourceName $lb.name  -Force

Script explanation

This script uses the following commands. Each command in the table links to command specific documentation.

Command Notes
Get-AzResource Gets the Microsoft.Network/loadBalancers resource.
Set-AzResource Updates the Microsoft.Network/loadBalancers resource.

Next steps

For more information on the Azure PowerShell module, see Azure PowerShell documentation.

Additional Azure Powershell samples for Azure Service Fabric can be found in the Azure PowerShell samples.