共用方式為


更新 RDP 連接埠範圍值

此指令碼範例會在叢集已部署完成之後,變更叢集節點 VM 上的 RDP 連接埠範圍值。 為了讓基礎 VM 不會循環,所以使用 Azure PowerShell。 此指令碼會取得叢集之資源群組中的 Microsoft.Network/loadBalancers 資源,並更新 inboundNatPools.frontendPortRangeStartinboundNatPools.frontendPortRangeEnd 值。 視需要自訂參數。

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 若要開始使用,請參閱 安裝 Azure PowerShell。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

您可以視需要使用 Azure PowerShell 指南 (英文) 中的指示來安裝 Azure PowerShell。

範例指令碼

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

指令碼說明

此指令碼會使用下列命令。 下表中的每個命令都會連結至命令特定的文件。

Command 注意
Get-AzResource 取得 Microsoft.Network/loadBalancers 資源。
Set-AzResource 更新 Microsoft.Network/loadBalancers 資源。

下一步

如需有關 Azure PowerShell 模組的詳細資訊,請參閱 Azure PowerShell 文件

您可以在 Azure PowerShell 範例中找到適用於 Azure Service Fabric 的其他 Azure PowerShell 範例。