Set-AzVMOperatingSystem

Sets operating system properties for a virtual machine.

Syntax

Set-AzVMOperatingSystem
   [-VM] <PSVirtualMachine>
   [-Windows]
   [-ComputerName] <String>
   [-Credential] <PSCredential>
   [[-CustomData] <String>]
   [-ProvisionVMAgent]
   [-EnableAutoUpdate]
   [[-TimeZone] <String>]
   [-WinRMHttp]
   [-PatchMode <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzVMOperatingSystem
   [-VM] <PSVirtualMachine>
   [-Windows]
   [-ComputerName] <String>
   [-Credential] <PSCredential>
   [[-CustomData] <String>]
   [-ProvisionVMAgent]
   [-EnableAutoUpdate]
   [[-TimeZone] <String>]
   [-WinRMHttp]
   [-WinRMHttps]
   [-WinRMCertificateUrl] <Uri>
   [-PatchMode <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzVMOperatingSystem
   [-VM] <PSVirtualMachine>
   [-Windows]
   [-ComputerName] <String>
   [-Credential] <PSCredential>
   [[-CustomData] <String>]
   [-DisableVMAgent]
   [-EnableAutoUpdate]
   [[-TimeZone] <String>]
   [-WinRMHttp]
   [-PatchMode <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzVMOperatingSystem
   [-VM] <PSVirtualMachine>
   [-Windows]
   [-ComputerName] <String>
   [-Credential] <PSCredential>
   [[-CustomData] <String>]
   [-DisableVMAgent]
   [-EnableAutoUpdate]
   [[-TimeZone] <String>]
   [-WinRMHttp]
   [-WinRMHttps]
   [-WinRMCertificateUrl] <Uri>
   [-PatchMode <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzVMOperatingSystem
   [-VM] <PSVirtualMachine>
   [-Linux]
   [-ComputerName] <String>
   [-Credential] <PSCredential>
   [[-CustomData] <String>]
   [-DisablePasswordAuthentication]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

The Set-AzVMOperatingSystem cmdlet sets operating system properties for a virtual machine. You can specify logon credentials, computer name, and operating system type.

Examples

Example 1: Set operating system properties for a new virtual machines

$SecurePassword = ConvertTo-SecureString "Password" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ("FullerP", $SecurePassword); 
$AvailabilitySet = Get-AzAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet03" 
$VirtualMachine = New-AzVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id
$ComputerName = "ContosoVM122"
$WinRMCertUrl = "http://keyVaultName.vault.azure.net/secrets/secretName/secretVersion"
$TimeZone = "Pacific Standard Time"
$CustomData = "echo 'Hello World'"
$VirtualMachine = Set-AzVMOperatingSystem -VM $$VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -CustomData $CustomData -WinRMHttp -WinRMHttps -WinRMCertificateUrl $WinRMCertUrl -ProvisionVMAgent -EnableAutoUpdate -TimeZone $TimeZone -PatchMode "AutomaticByPlatform"

The first command converts a password to a secure string, and then stores it in the $SecurePassword variable. For more information, type Get-Help ConvertTo-SecureString. The second command creates a credential for the user FullerP and the password stored in $SecurePassword, and then stores the credential in the $Credential variable. For more information, type Get-Help New-Object. The third command gets the availability set named AvailabilitySet03 in the resource group named ResourceGroup11, and then stores that object in the $AvailabilitySet variable. The fourth command creates a virtual machine object, and then stores it in the $VirtualMachine variable. The command assigns a name and size to the virtual machine. The virtual machine belongs to the availability set stored in $AvailabilitySet. The next four commands assign values to variables to use in the following command. Because you could specify these strings directly in the Set-AzVMOperatingSystem command, this approach is used only for readability. However, you might use an approach such as this in scripts. The final command sets operating system properties for the virtual machine stored in $VirtualMachine. The command uses the credentials stored in $Credential. The command uses variables assigned in previous commands for some parameters.

Parameters

-ComputerName

Specifies the name of the computer.

Type:String
Position:2
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-Credential

Specifies the user name and password for the virtual machine as a PSCredential object. To obtain a credential, use the Get-Credential cmdlet. For more information, type Get-Help Get-Credential.

Type:PSCredential
Position:3
Default value:None
Accept pipeline input:True
Accept wildcard characters: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.
Note: Do not pass any secrets or passwords in customData property
This property cannot be updated after the VM is created.
customData is passed to the VM to be saved as a file, for more information see Custom Data on Azure VMs
For using cloud-init for your Linux VM, see Using cloud-init to customize a Linux VM during creation

Type:String
Position:4
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-DefaultProfile

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

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DisablePasswordAuthentication

Indicates that this cmdlet disables password authentication.

Type:SwitchParameter
Position:5
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-DisableVMAgent

Disable Provision VM Agent.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-EnableAutoUpdate

Indicates that this cmdlet enables auto update.

Type:SwitchParameter
Position:6
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-Linux

Indicates that the type of operating system is Linux.

Type:SwitchParameter
Position:1
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-PatchMode

Specifies the mode of in-guest patching to IaaS virtual machine.

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 OS. The properties provisionVMAgent and WindowsConfiguration.enableAutomaticUpdates must be true

Type:String
Position:Named
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-ProvisionVMAgent

Indicates that the settings require that the virtual machine agent be installed on the virtual machine.

Type:SwitchParameter
Position:5
Default value:None
Accept pipeline input:True
Accept wildcard characters: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.

Type:String
Position:7
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-VM

Specifies the local virtual machine object on which to set operating system properties. To obtain a virtual machine object, use the Get-AzVM cmdlet. Create a virtual machine object by using the New-AzVMConfig cmdlet.

Type:PSVirtualMachine
Aliases:VMProfile
Position:0
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-Windows

Indicates that the type of operating system is Windows.

Type:SwitchParameter
Position:1
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-WinRMCertificateUrl

Specifies the URI of a WinRM certificate. This needs to be stored in a Key Vault.

Type:Uri
Position:10
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-WinRMHttp

Indicates that this operating system uses HTTP WinRM.

Type:SwitchParameter
Position:8
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
-WinRMHttps

Indicates that this operating system uses HTTPS WinRM.

Type:SwitchParameter
Position:9
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

Inputs

PSVirtualMachine

SwitchParameter

String

PSCredential

Uri

Outputs

PSVirtualMachine