Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
Set-AzVMOperatingSystem
- Module:
- Az.Compute Module
Sets operating system properties during the creation of a new virtual machine or updating a virtual machine.
Syntax
Windows (Default)
Set-AzVMOperatingSystem
[-VM] <PSVirtualMachine>
[[-ComputerName] <String>]
[[-Credential] <PSCredential>]
[[-CustomData] <String>]
[[-TimeZone] <String>]
[-Windows]
[-ProvisionVMAgent]
[-EnableAutoUpdate]
[-WinRMHttp]
[-PatchMode <String>]
[-EnableHotpatching]
[-AssessmentMode <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
WindowsWinRmHttps
Set-AzVMOperatingSystem
[-VM] <PSVirtualMachine>
[[-ComputerName] <String>]
[[-Credential] <PSCredential>]
[[-CustomData] <String>]
[[-TimeZone] <String>]
[-WinRMCertificateUrl] <Uri>
[-Windows]
[-ProvisionVMAgent]
[-EnableAutoUpdate]
[-WinRMHttp]
[-WinRMHttps]
[-PatchMode <String>]
[-EnableHotpatching]
[-AssessmentMode <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
WindowsDisableVMAgent
Set-AzVMOperatingSystem
[-VM] <PSVirtualMachine>
[[-ComputerName] <String>]
[[-Credential] <PSCredential>]
[[-CustomData] <String>]
[[-TimeZone] <String>]
[-Windows]
[-DisableVMAgent]
[-EnableAutoUpdate]
[-WinRMHttp]
[-PatchMode <String>]
[-EnableHotpatching]
[-AssessmentMode <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
WindowsDisableVMAgentWinRmHttps
Set-AzVMOperatingSystem
[-VM] <PSVirtualMachine>
[[-ComputerName] <String>]
[[-Credential] <PSCredential>]
[[-CustomData] <String>]
[[-TimeZone] <String>]
[-WinRMCertificateUrl] <Uri>
[-Windows]
[-DisableVMAgent]
[-EnableAutoUpdate]
[-WinRMHttp]
[-WinRMHttps]
[-PatchMode <String>]
[-EnableHotpatching]
[-AssessmentMode <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Linux
Set-AzVMOperatingSystem
[-VM] <PSVirtualMachine>
[[-ComputerName] <String>]
[[-Credential] <PSCredential>]
[[-CustomData] <String>]
[-Linux]
[-PatchMode <String>]
[-DisablePasswordAuthentication]
[-AssessmentMode <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
The Set-AzVMOperatingSystem cmdlet sets operating system properties during the creation of a new virtual machine. You can specify logon credentials, computer name, and operating system type.
Examples
Example 1: Set operating system properties for a new virtual machine
$SecurePassword = ConvertTo-SecureString -String "****" -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.
Example 2: Set operating system properties for a new virtual machine with hot patching enabled
$SecurePassword = ConvertTo-SecureString -String "****" -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" -EnableHotPatching
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.
The command enables Hotpatching on the virtual machine.
Example 3: Set operating system properties for a new Linux virtual machine
$SecurePassword = ConvertTo-SecureString -String "****" -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"
$CustomData = "echo 'Hello World'"
$VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Linux -ComputerName $ComputerName -Credential $Credential -CustomData $CustomData -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 two commands assign values to variables to use in the following command.
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.
The command sets the patch mode value on the virtual machine to "AutomaticByPlatform".
Example 4: Set operating system properties with a Credential parameter when the VM does not have an OSProfile.
$rgname = <Resource Group Name>;
$loc = <Azure Region>;
New-AzResourceGroup -Name $rgname -Location $loc -Force;
# create credential
$password = <Password>;
$securePassword = $password | ConvertTo-SecureString -AsPlainText -Force;
$user = <Username>;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
# Setup parameters
$domainNameLabel = "d2" + $rgname;
$vmsize = 'Standard_D4s_v3';
$vmname = 'v' + $rgname;
$vnetname = "vn" + $rgname;
$vnetAddress = "10.0.0.0/16";
$subnetname = "slb" + $rgname;
$subnetAddress = "10.0.2.0/24";
$OSDiskName = $vmname + "d";
$NICName = $vmname+ "n";
$NSGName = $vmname + "nsg";
# Creating a VM using Default parameterset
$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetname -AddressPrefix $subnetAddress;
$vnet = New-AzVirtualNetwork -Name $vnetname -ResourceGroupName $rgname -Location $loc -AddressPrefix $vnetAddress -Subnet $frontendSubnet;
$nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name RDP -Protocol Tcp -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow;
$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $rgname -Location $loc -Name $NSGName -SecurityRules $nsgRuleRDP;
$nic = New-AzNetworkInterface -Name $NICName -ResourceGroupName $rgname -Location $loc -SubnetId $vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id -EnableAcceleratedNetworking;
$vmConfig = New-AzVMConfig -VMName $vmname -VMSize $vmsize;
$vmConfig = Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $vmname -Credential $cred;
$vmConfig = Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id;
# Verify a VM is created.
New-AzVM -ResourceGroupName $rgname -Location $loc -VM $vmConfig;
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;
Parameters
-AssessmentMode
Automatic assessment mode value for the virtual machine. Possible values are ImageDefault and AutomaticByPlatform.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-ComputerName
Specifies the name of the computer.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-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.
Parameter properties
| Type: | PSCredential |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-CustomData
Specifies a string to be passed to the virtual machine. For more information see Custom Data on Azure VMs. Note: It is not recommended to store sensitive information in custom data.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-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
-DisablePasswordAuthentication
Indicates that this cmdlet disables password authentication.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-DisableVMAgent
Disable Provision VM Agent.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-EnableAutoUpdate
Indicates that this cmdlet enables auto update.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-EnableHotpatching
Enables customers to patch their Azure VMs 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
-Linux
Indicates that the type of operating system is Linux.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-PatchMode
Specifies the mode of in-guest patching to IaaS virtual machine.
Possible values are:
AutomaticByPlatform - Patch installation for the virtual machine will be managed by Azure. Use with -Windows or -Linux. Requires -ProvisionVMAgent. Requires -EnableAutoUpdate when used with -Windows.
AutomaticByOS - Patch installation for the virtual machine will be managed by the OS. Use with -Windows. Requires -ProvisionVMAgent and -EnableAutoUpdate.
Manual - You control the application of patches to a virtual machine. Use with -Windows. Requires -ProvisionVMAgent.
ImageDefault - Patch installation managed by the default settings on the OS image. Use with -Linux.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-ProvisionVMAgent
Indicates that the settings require that the virtual machine agent be installed on the virtual machine.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-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
-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.
Parameter properties
| Type: | PSVirtualMachine |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | VMProfile |
Parameter sets
-Windows
Indicates that the type of operating system is Windows.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-WinRMCertificateUrl
Specifies the URI of a WinRM certificate. This needs to be stored in a Key Vault.
Parameter properties
| Type: | Uri |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-WinRMHttp
Indicates that this operating system uses HTTP WinRM.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-WinRMHttps
Indicates that this operating system uses HTTPS WinRM.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
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
PSVirtualMachine
SwitchParameter
String
PSCredential
Uri
Outputs
PSVirtualMachine
Related Links
Azure PowerShell
Feedback
Was this page helpful?
