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 cluster's resource group and updates the inboundNatPools.frontendPortRangeStart and inboundNatPools.frontendPortRangeEnd values. Customize the parameters as needed.

Note

This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.

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

Sample script

Login-AzAccount
Get-AzSubscription
Set-AzContext -SubscriptionId 'yourSubscriptionId'

$groupname = "mysfclustergroup"
$start=3400
$end=4400

# 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.