更新 RDP 端口范围值Update the RDP port range values

部署群集后,此示例脚本可更改群集节点 VM 上的 RDP 端口范围值。This sample script changes the RDP port range values on the cluster node VMs after the cluster has been deployed. 使用了 Azure PowerShell,使底层 VM 不会重启。Azure PowerShell is used so that the underlying VMs do not cycle. 该脚本会获取群集资源组中的 Microsoft.Network/loadBalancers 资源,并更新 inboundNatPools.frontendPortRangeStartinboundNatPools.frontendPortRangeEnd 值。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.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

必要时,请使用 Azure PowerShell 指南中的说明安装 Azure PowerShell。If needed, install the Azure PowerShell using the instruction found in the Azure PowerShell guide.

示例脚本Sample script

Connect-AzAccount -Environment AzureChinaCloud
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.

CommandCommand 说明Notes
Get-AzResourceGet-AzResource 获取 Microsoft.Network/loadBalancers 资源。Gets the Microsoft.Network/loadBalancers resource.
Set-AzResourceSet-AzResource 更新 Microsoft.Network/loadBalancers 资源。Updates the Microsoft.Network/loadBalancers resource.

后续步骤Next steps

有关 Azure PowerShell 模块的详细信息,请参阅 Azure PowerShell 文档For more information on the Azure PowerShell module, see Azure PowerShell documentation.

可以在 Azure PowerShell 示例中找到 Azure Service Fabric 的其他 Azure Powershell 示例。Additional Azure Powershell samples for Azure Service Fabric can be found in the Azure PowerShell samples.