更新群集中 VM 的管理员用户名和密码Update the admin username and password of the VMs in a cluster

Service Fabric 群集中的每个节点类型是一个虚拟机规模集。Each node type in a Service Fabric cluster is a virtual machine scale set. 此示例脚本更新特定节点类型中群集虚拟机的管理员用户名和密码。This sample script updates the admin username and password for the cluster virtual machines in a specific node type. 将 VMAccessAgent 扩展添加到规模集,因为管理员密码是不可修改的规模集属性。Add the VMAccessAgent extension to the scale set, because the admin password is not a modifiable scale set property. 用户名和密码更改将应用到规模集中的所有节点。The username and password changes apply to all nodes in the scale set. 根据需要自定义参数。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'

$nodeTypeName = 'nt1vm'
$resourceGroup = 'sfclustertutorialgroup'
$publicConfig = @{'UserName' = 'newuser'}
$privateConfig = @{'Password' = 'PasSwo0rd$#!'}
$extName = 'VMAccessAgent'
$publisher = 'Microsoft.Compute'
$node = Get-AzVmss -ResourceGroupName $resourceGroup -VMScaleSetName $nodeTypeName
$node = Add-AzVmssExtension -VirtualMachineScaleSet $node -Name $extName -Publisher $publisher -Setting $publicConfig -ProtectedSetting $privateConfig -Type $extName -TypeHandlerVersion '2.0' -AutoUpgradeMinorVersion $true

Update-AzVmss -ResourceGroupName $resourceGroup -Name $nodeTypeName -VirtualMachineScaleSet $node

脚本说明Script explanation

此脚本使用以下命令:表中的每条命令均链接到特定于命令的文档。This script uses the following commands: Each command in the table links to command specific documentation.

CommandCommand 说明Notes
Get-AzVmssGet-AzVmss 获取群集节点类型(虚拟机规模集)的属性。Gets the properties of a cluster node type (a virtual machine scale set).
Add-AzVmssExtensionAdd-AzVmssExtension 将扩展添加到虚拟机规模集。Adds an extension to the virtual machine scale set.
Update-AzVmssUpdate-AzVmss 将虚拟机规模集的状态更新为 VMSS 对象的状态。Updates the state of a virtual machine scale set to the state of a local VMSS object.

DurationDuration

对于单节点类型,例如,如果有五个节点,那么更改用户名或密码的持续时间为 45 到 60 分钟。A single node type with five nodes, for example, has a duration of 45 to 60 minutes to change the username or password.

后续步骤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.