Set-​Azure​Rm​VM​OS​Disk

Sets the operating system disk properties on a virtual machine.

Syntax

Set-AzureRmVMOSDisk
   [-VM] <PSVirtualMachine>
   [[-Name] <String>]
   [[-KeyEncryptionKeyVaultId] <String>]
   [[-VhdUri] <String>]
   [[-Caching] <CachingTypes>]
   [[-SourceImageUri] <String>]
   [-CreateOption] <DiskCreateOptionTypes>
   [-Windows]
   [-DiskEncryptionKeyUrl] <String>
   [-DiskEncryptionKeyVaultId] <String>
   [[-KeyEncryptionKeyUrl] <String>]
   [-DiskSizeInGB <Int32>]
   [-ManagedDiskId <String>]
   [-StorageAccountType <StorageAccountTypes>]
   [<CommonParameters>]
Set-AzureRmVMOSDisk
   [-VM] <PSVirtualMachine>
   [[-Name] <String>]
   [[-KeyEncryptionKeyVaultId] <String>]
   [[-VhdUri] <String>]
   [[-Caching] <CachingTypes>]
   [[-SourceImageUri] <String>]
   [-CreateOption] <DiskCreateOptionTypes>
   [-Linux]
   [-DiskEncryptionKeyUrl] <String>
   [-DiskEncryptionKeyVaultId] <String>
   [[-KeyEncryptionKeyUrl] <String>]
   [-DiskSizeInGB <Int32>]
   [-ManagedDiskId <String>]
   [-StorageAccountType <StorageAccountTypes>]
   [<CommonParameters>]
Set-AzureRmVMOSDisk
   [-VM] <PSVirtualMachine>
   [[-Name] <String>]
   [[-VhdUri] <String>]
   [[-Caching] <CachingTypes>]
   [[-SourceImageUri] <String>]
   [-CreateOption] <DiskCreateOptionTypes>
   [-Linux]
   [-DiskSizeInGB <Int32>]
   [-ManagedDiskId <String>]
   [-StorageAccountType <StorageAccountTypes>]
   [<CommonParameters>]
Set-AzureRmVMOSDisk
   [-VM] <PSVirtualMachine>
   [[-Name] <String>]
   [[-VhdUri] <String>]
   [[-Caching] <CachingTypes>]
   [[-SourceImageUri] <String>]
   [-CreateOption] <DiskCreateOptionTypes>
   [-Windows]
   [-DiskSizeInGB <Int32>]
   [-ManagedDiskId <String>]
   [-StorageAccountType <StorageAccountTypes>]
   [<CommonParameters>]

Description

The Set-AzureRmVMOSDisk cmdlet set the operating system disk properties on a virtual machine.

Examples

Example 1: Set properties on a virtual machine from platform image

PS C:\> $AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet13" 
PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine17" -VMSize "Standard_A1" -AvailabilitySetID $AvailabilitySet.Id 
PS C:\> Set-AzureRmVMOSDisk -VM $VirtualMachine -Name "OsDisk12" -VhdUri "os.vhd" -Caching ReadWrite
PS C:\> $VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Linux -ComputerName "MainComputer" -Credential (Get-Credential) 
PS C:\> $VirtualMachine = Set-AzureRmVMSourceImage -VM $VirtualMachine -PublisherName "Canonical" -Offer "UbuntuServer" -Skus "15.10" -Version "latest" -Caching ReadWrite
PS C:\> $VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name "osDisk.vhd" -VhdUri "https://mystorageaccount.blob.core.windows.net/disks/" -CreateOption FromImage
PS C:> New-AzureRmVM -VM $VirtualMachine -ResouceGroupName "ResourceGroup11"

The first command gets the availability set named AvailablitySet13 in the resource group named ResourceGroup11, and then stores that object in the $AvailabilitySet variable. The second 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 final command sets the properties on the virtual machine in $VirtualMachine.

Example 2: Sets properties on a virtual machine from generalized user image

PS C:\> $AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet13" 
PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine17" -VMSize "Standard_A1"
PS C:\> $VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Linux -ComputerName "MainComputer" -Credential (Get-Credential)
PS C:\> $VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name "osDisk.vhd" -SourceImageUri "https://mystorageaccount.blob.core.windows.net/vhds/myOSImage.vhd" -VhdUri "https://mystorageaccount.blob.core.windows.net/disks/" -CreateOption fromImage -Linux
PS C:> New-AzureRmVM -VM $VirtualMachine -ResouceGroupName "ResourceGroup11"

The first command gets the availability set named AvailablitySet13 in the resource group named ResourceGroup11 and stores that object in the $AvailabilitySet variable. The second command creates a virtual machine object and 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 final command sets the properties on the virtual machine in $VirtualMachine.

Example 3: Sets properties on a virtual machine from specialized user image

PS C:\> $AvailabilitySet = Get-AzureRmAvailabilitySet -ResourceGroupName "ResourceGroup11" -Name "AvailabilitySet13" 
PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine17" -VMSize "Standard_A1"
PS C:\> $VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name "osDisk.vhd" -VhdUri "https://mystorageaccount.blob.core.windows.net/disks/" -CreateOption Attach -Linux
PS C:> New-AzureRmVM -VM $VirtualMachine -ResouceGroupName "ResourceGroup11"

The first command gets the availability set named AvailablitySet13 in the resource group named ResourceGroup11 and stores that object in the $AvailabilitySet variable. The second command creates a virtual machine object and 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 final command sets the properties on the virtual machine in $VirtualMachine.

Example 4: Set the disk encryption settings on a virtual machine operating system disk

PS C:\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine17" -VMSize "Standard_A1"
PS C:> $VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name "OsDisk12" -VhdUri "os.vhd" -Caching ReadWrite -Windows -CreateOption "Attach" -DiskEncryptionKeyUrl "https://mytestvault.vault.azure.net/secrets/Test1/514ceb769c984379a7e0230bddaaaaaa" -DiskEncryptionKeyVaultId "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.KeyVault/vaults/mytestvault"
PS C:> New-AzureRmVM -VM $VirtualMachine -ResouceGroupName " ResourceGroup11"

This example sets the disk encryption settings on a virtual machine operating system disk.

Required Parameters

-CreateOption

Specifies whether this cmdlet creates a disk in the virtual machine from a platform or user image, or attaches an existing disk. Valid values are:

  • Attach. Specify this option to create a virtual machine from a specialized disk. When you specify this option, do not specify the SourceImageUri parameter. Instead, use the Set-AzureRmVMSourceImage cmdlet. You must also use the use the Windows or Linux parameters to tell the azure2 platform the type of the operating system on the VHD. The VhdUri parameter is enough to tell the azure2 platform the location of the disk to attach.
  • FromImage. Specify this option to create a virtual machine from a platform image or a generalized user image. In the case of a generalized user image, you also need to specify the SourceImageUri parameter and either the Windows or Linux parameters to tell the Azure platform the location and type of the operating system disk VHD instead of using the Set-AzureRmVMSourceImage cmdlet. In the case of a platform image, the VhdUri parameter is sufficient.
  • Empty.
Type:DiskCreateOptionTypes
Parameter Sets:FromImage, Empty, Attach
Position:5
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-DiskEncryptionKeyUrl

Specifies the location of the disk encryption key.

Type:String
Position:7
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-DiskEncryptionKeyVaultId

Specifies the resource ID of the Key Vault containing the disk encryption key.

Type:String
Position:8
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-VM

Specifies the local virtual machine object on which to set operating system disk properties. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet.

Type:PSVirtualMachine
Aliases:VMProfile
Position:0
Default value:None
Accept pipeline input:True (ByPropertyName, ByValue)
Accept wildcard characters:False

Optional Parameters

-Caching

Specifies the caching mode of the operating system disk. Valid values are:

  • ReadOnly
  • ReadWrite

The default value is ReadWrite. Changing the caching value causes the virtual machine to restart.

This setting affects the performance of the disk.

Type:CachingTypes
Parameter Sets:None, ReadOnly, ReadWrite
Position:3
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-DiskSizeInGB

Specifies the size, in GB, of the operating system disk.

Type:Int32
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-KeyEncryptionKeyUrl

Specifies the location of the key encryption key.

Type:String
Position:9
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-KeyEncryptionKeyVaultId

Specifies the resource ID of the Key Vault containing the key encryption key.

Type:String
Position:10
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Linux

Indicates that the operating system on the user image is Linux. Specify this parameter for user image based virtual machine deployment.

Type:SwitchParameter
Position:6
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-ManagedDiskId

Specifies the ID of a managed disk.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Name

Specifies the name of the operating system disk.

Type:String
Aliases:OSDiskName, DiskName
Position:1
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-SourceImageUri

Specifies the URI of the VHD for user image scenarios.

Type:String
Aliases:SourceImage
Position:4
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-StorageAccountType

Specifies the storage account type of managed disk.

Type:StorageAccountTypes
Parameter Sets:StandardLRS, PremiumLRS
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-VhdUri

Specifies the Uniform Resource Identifier (URI) of a virtual hard disk (VHD).

For an image based virtual machine, this parameter specifies the VHD file to create when a platform image or user image is specified. This is the location from which the image binary large object (BLOB) is copied to start the virtual machine.

For a disk based virtual machine boot scenario, this parameter specifies the VHD file that the virtual machine uses directly for starting up.

Type:String
Aliases:OSDiskVhdUri, DiskVhdUri
Position:2
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Windows

Indicates that the operating system on the user image is Windows.

Type:SwitchParameter
Position:6
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False