Edit

Share via


Set-AzVmssOsProfile

Sets the VMSS operating system profile properties.

Syntax

Default (Default)

Set-AzVmssOsProfile
    [-VirtualMachineScaleSet] <PSVirtualMachineScaleSet>
    [[-ComputerNamePrefix] <String>]
    [[-AdminUsername] <String>]
    [[-AdminPassword] <String>]
    [[-CustomData] <String>]
    [[-WindowsConfigurationProvisionVMAgent] <Boolean>]
    [-LinuxConfigurationProvisionVMAgent <Boolean>]
    [[-WindowsConfigurationEnableAutomaticUpdate] <Boolean>]
    [[-TimeZone] <String>]
    [[-AdditionalUnattendContent] <AdditionalUnattendContent[]>]
    [[-Listener] <WinRMListener[]>]
    [[-LinuxConfigurationDisablePasswordAuthentication] <Boolean>]
    [[-PublicKey] <SshPublicKey[]>]
    [[-Secret] <VaultSecretGroup[]>]
    [-WindowsConfigurationPatchMode <String>]
    [-LinuxConfigurationPatchMode <String>]
    [-EnableHotpatching]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Set-AzVmssOsProfile cmdlet sets the Virtual Machine Scale Set operating system profile properties.

Examples

Example 1: Set the operating system profile properties for a VMSS

$vmss = New-AzVmssConfig -Location $Loc -SkuCapacity 2 -SkuName "Standard_A0" -UpgradePolicyMode "Automatic" -NetworkInterfaceConfiguration $NetCfg
Set-AzVmssOsProfile -VirtualMachineScaleSet $vmss -ComputerNamePrefix "Test" -AdminUsername $AdminUsername -AdminPassword $AdminPassword

This command sets operating system profile properties for the $vmss object. The command sets the computer name prefix for all the virtual machine instances in the VMSS to Test and supplies the administrator username and password.

Example 2: Set the operating system profile properties for a Vmss in Flexible mode with Hotpatching enabled.

# Setup variables.
$loc = "eastus";
$rgname = "<Resource Group Name>";
$vmssName = "myVmssSlb";
$vmNamePrefix = "vmSlb";
$vmssInstanceCount = 5;
$vmssSku = "Standard_DS1_v2";
$vnetname = "myVnet";
$vnetAddress = "10.0.0.0/16";
$subnetname = "default-slb";
$subnetAddress = "10.0.2.0/24";
$securePassword = ConvertTo-SecureString -String "****" -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ("<Username>", $securePassword);

# VMSS Flex requires explicit outbound access.
# Create a virtual network.
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetname -AddressPrefix $subnetAddress;
$virtualNetwork = New-AzVirtualNetwork -Name $vnetname -ResourceGroupName $rgname -Location $loc -AddressPrefix $vnetAddress -Subnet $frontendSubnet;

# Create a public IP address.
$publicIP = New-AzPublicIpAddress `
    -ResourceGroupName $rgname `
    -Location $loc `
    -AllocationMethod Static `
    -Sku "Standard" `
    -IpAddressVersion "IPv4" `
    -Name "myLBPublicIP";

# Create a frontend and backend IP pool.
$frontendIP = New-AzLoadBalancerFrontendIpConfig `
    -Name "myFrontEndPool" `
    -PublicIpAddress $publicIP;

$backendPool = New-AzLoadBalancerBackendAddressPoolConfig -Name "myBackEndPool" ;

# Create the load balancer.
$lb = New-AzLoadBalancer `
    -ResourceGroupName $rgname `
    -Name "myLoadBalancer" `
    -Sku "Standard" `
    -Tier "Regional" `
    -Location $loc `
    -FrontendIpConfiguration $frontendIP `
    -BackendAddressPool $backendPool;

# Create a load balancer health probe for TCP port 80.
Add-AzLoadBalancerProbeConfig -Name "myHealthProbe" `
    -LoadBalancer $lb `
    -Protocol TCP `
    -Port 80 `
    -IntervalInSeconds 15 `
    -ProbeCount 2;

# Create a load balancer rule to distribute traffic on port TCP 80.
# The health probe from the previous step is used to make sure that traffic is
# only directed to healthy VM instances.
Add-AzLoadBalancerRuleConfig `
    -Name "myLoadBalancerRule" `
    -LoadBalancer $lb `
    -FrontendIpConfiguration $lb.FrontendIpConfigurations[0] `
    -BackendAddressPool $lb.BackendAddressPools[0] `
    -Protocol TCP `
    -FrontendPort 80 `
    -BackendPort 80 `
    -DisableOutboundSNAT `
    -Probe (Get-AzLoadBalancerProbeConfig -Name "myHealthProbe" -LoadBalancer $lb);

# Add outbound connectivity rule.
Add-AzLoadBalancerOutboundRuleConfig `
    -Name "outboundrule" `
    -LoadBalancer $lb `
    -AllocatedOutboundPort '10000' `
    -Protocol 'All' `
    -IdleTimeoutInMinutes '15' `
    -FrontendIpConfiguration $lb.FrontendIpConfigurations[0] `
    -BackendAddressPool $lb.BackendAddressPools[0];

# Update the load balancer configuration.
Set-AzLoadBalancer -LoadBalancer $lb;

# Create IP address configurations.
# Instances will require explicit outbound connectivity, for example
#   - NAT Gateway on the subnet (recommended)
#   - Instances in backend pool of Standard LB with outbound connectivity rules
#   - Public IP address on each instance
# See aka.ms/defaultoutboundaccess for more info.
$ipConfig = New-AzVmssIpConfig `
    -Name "myIPConfig" `
    -SubnetId $virtualNetwork.Subnets[0].Id `
    -LoadBalancerBackendAddressPoolsId $lb.BackendAddressPools[0].Id `
    -Primary;

# Create a config object.
# The Vmss config object stores the core information for creating a scale set.
$vmssConfig = New-AzVmssConfig `
    -Location $loc `
    -SkuCapacity $vmssInstanceCount `
    -SkuName $vmssSku `
    -OrchestrationMode 'Flexible' `
    -PlatformFaultDomainCount 1;

# Reference a virtual machine image from the gallery.
Set-AzVmssStorageProfile $vmssConfig `
    -OsDiskCreateOption "FromImage" `
    -ImageReferencePublisher "MicrosoftWindowsServer" `
    -ImageReferenceOffer "WindowsServer" `
    -ImageReferenceSku "2022-datacenter-azure-edition-core-smalldisk" `
    -ImageReferenceVersion "latest";

# Set up information for authenticating with the virtual machine.
Set-AzVmssOsProfile $vmssConfig `
    -AdminUsername $cred.UserName `
    -AdminPassword $cred.Password `
    -ComputerNamePrefix $vmNamePrefix `
    -WindowsConfigurationProvisionVMAgent $true `
    -WindowsConfigurationPatchMode "AutomaticByPlatform" `
    -EnableHotpatching;

# Attach the virtual network to the config object.
Add-AzVmssNetworkInterfaceConfiguration `
    -VirtualMachineScaleSet $vmssConfig `
    -Name "network-config" `
    -Primary $true `
    -IPConfiguration $ipConfig `
    -NetworkApiVersion '2020-11-01';

# Define the Application Health extension properties.
$publicConfig = @{"protocol" = "http"; "port" = 80; "requestPath" = "/healthEndpoint"};
$extensionName = "myHealthExtension";
$extensionType = "ApplicationHealthWindows";
$publisher = "Microsoft.ManagedServices";
# Add the Application Health extension to the scale set model.
Add-AzVmssExtension -VirtualMachineScaleSet $vmssConfig `
    -Name $extensionName `
    -Publisher $publisher `
    -Setting $publicConfig `
    -Type $extensionType `
    -TypeHandlerVersion "1.0" `
    -AutoUpgradeMinorVersion $True;

# Create the virtual machine scale set.
$vmss = New-AzVmss `
    -ResourceGroupName $rgname `
    -Name $vmssName `
    -VirtualMachineScaleSet $vmssConfig;

Set the operating system profile properties for a Vmss in Flexible mode with Hotpatching enabled

Parameters

-AdditionalUnattendContent

Specifies an unattended content object. You can use the Add-AzVMAdditionalUnattendContent to create the object.

Parameter properties

Type:

AdditionalUnattendContent[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:8
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-AdminPassword

Specifies the administrator password to use for all the virtual machine instances in the VMSS.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:3
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-AdminUsername

Specifies the administrator account name to use for all the virtual machine instances in the VMSS.
Restriction:
Windows: Cannot contain special characters /""[]:|<>+=;,?*@& or end in "."
Linux: Username must only contain letters, numbers, hyphens, and underscores and may not start with a hyphen or number.
Disallowed values: "administrator", "admin", "user", "user1", "test", "user2", "test1", "user3", "admin1", "1", "123", "a", "actuser", "adm", "admin2", "aspnet", "backup", "console", "david", "guest", "john", "owner", "root", "server", "sql", "support", "support_388945a0", "sys", "test2", "test3", "user4", "user5".
Minimum-length: 1 character
Max-length: 20 characters for Windows, 64 characters for Linux
For a list of built-in system users on Linux that should not be used in this field, see Selecting User Names for Linux on Azure.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:2
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ComputerNamePrefix

Specifies the computer name prefix for all the virtual machine instances in the VMSS. Computer names must be 1 to 15 characters long.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:1
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-CustomData

Specifies a base-64 encoded string of custom data. This is decoded to a binary array that is saved as a file on the virtual machine. The maximum length of the binary array is 65535 bytes.
For using cloud-init for your VM, see Using cloud-init to customize a Linux VM during creation.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:4
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-EnableHotpatching

Enables customers to patch their Azure Vmss without requiring a reboot. For enableHotpatching, the 'provisionVMAgent' must be set to true and 'patchMode' must be set to 'AutomaticByPlatform'.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-LinuxConfigurationDisablePasswordAuthentication

Indicates that this cmdlet disables password authentication.

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:10
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-LinuxConfigurationPatchMode

Specifies the mode of VM Guest Patching to IaaS virtual machine or virtual machines associated to virtual machine scale set with OrchestrationMode as Flexible.

Possible values are:

ImageDefault - The virtual machine's default patching configuration is used.

AutomaticByPlatform - The virtual machine will be automatically updated by the platform. The property provisionVMAgent must be true

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-LinuxConfigurationProvisionVMAgent

Indicates whether virtual machine agent should be provisioned on the virtual machine.

When this property is not specified in the request body, default behavior is to set it to true. This will ensure that VM Agent is installed on the VM so that extensions can be added to the VM later

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Listener

Specifies the Windows Remote Management (WinRM) listeners. This enables remote Windows PowerShell. You can use the Add-AzVmssWinRMListener cmdlet to create the listener.

Parameter properties

Type:

WinRMListener[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:9
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-PublicKey

Specifies the Secure Shell (SSH) public key object. You can use the Add-AzVMSshPublicKey cmdlet to create the object.

Parameter properties

Type:

SshPublicKey[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:11
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Secret

Specifies the secrets object which contains the certificate references to place on the virtual machine. You can use the Add-AzVmssSecret cmdlet to create the secrets object.

Parameter properties

Type:

VaultSecretGroup[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:12
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-TimeZone

Specifies the time zone of the virtual machine. e.g. "Pacific Standard Time".
Possible values can be TimeZoneInfo.Id value from time zones returned by TimeZoneInfo.GetSystemTimeZones.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:7
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-VirtualMachineScaleSet

Specifies the VMSS object. You can use the New-AzVmssConfig cmdlet to create the object.

Parameter properties

Type:PSVirtualMachineScaleSet
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WindowsConfigurationEnableAutomaticUpdate

Indicates whether the virtual machines in the VMSS are enabled for automatic updates.

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:6
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-WindowsConfigurationPatchMode

Specifies the mode of VM Guest Patching to IaaS virtual machine or virtual machines associated to virtual machine scale set with OrchestrationMode as Flexible.

Possible values are:

Manual - You control the application of patches to a virtual machine. You do this by applying patches manually inside the VM. In this mode, automatic updates are disabled; the property WindowsConfiguration.enableAutomaticUpdates must be false

AutomaticByOS - The virtual machine will automatically be updated by the OS. The property WindowsConfiguration.enableAutomaticUpdates must be true.

AutomaticByPlatform - the virtual machine will automatically updated by the platform. The properties provisionVMAgent and WindowsConfiguration.enableAutomaticUpdates must be true

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-WindowsConfigurationProvisionVMAgent

Indicates whether virtual machine agent should be provisioned on the virtual machines in the VMSS.

Parameter properties

Type:

Nullable<T>[Boolean]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:5
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

PSVirtualMachineScaleSet

String

Nullable<T>

AdditionalUnattendContent

WinRMListener

SshPublicKey

VaultSecretGroup

Outputs

PSVirtualMachineScaleSet