更新 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 Az PowerShell 模块。This article has been updated to use the Azure Az PowerShell module. 若要与 Azure 交互,建议使用的 PowerShell 模块是 Az PowerShell 模块。The Az PowerShell module is the recommended PowerShell module for interacting with Azure. 若要开始使用 Az PowerShell 模块,请参阅安装 Azure PowerShellTo get started with the Az PowerShell module, see Install Azure PowerShell. 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 AzTo learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

必要时,请使用 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.