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.
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.
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.
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'.
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
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
Specifies the Windows Remote Management (WinRM) listeners.
This enables remote Windows PowerShell.
You can use the Add-AzVmssWinRMListener cmdlet to create the listener.
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.
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
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.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.