Update the admin username and password of the VMs in a cluster

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

Note

We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

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'

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

Command Notes
Get-AzVmss Gets the properties of a cluster node type (a virtual machine scale set).
Add-AzVmssExtension Adds an extension to the virtual machine scale set.
Update-AzVmss Updates the state of a virtual machine scale set to the state of a local VMSS object.

Duration

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

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.