Set-AzureRMVMDataDisk

Modifies properties of a virtual machine data disk.

Warning

The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and updates.

Although the AzureRM module may still function, it's no longer maintained or supported, placing any continued use at the user's discretion and risk. Please refer to our migration resources for guidance on transitioning to the Az module.

Syntax

Set-AzureRMVMDataDisk
   [-VM] <PSVirtualMachine>
   [-Name] <String>
   [[-Caching] <CachingTypes>]
   [[-DiskSizeInGB] <Int32>]
   [-StorageAccountType <String>]
   [-WriteAccelerator]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzureRMVMDataDisk
   [-VM] <PSVirtualMachine>
   [-Lun] <Int32>
   [[-Caching] <CachingTypes>]
   [[-DiskSizeInGB] <Int32>]
   [-StorageAccountType <String>]
   [-WriteAccelerator]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

The Set-AzureRmVMDataDisk cmdlet modifies properties of a virtual machine data disk.

Examples

Example 1: Modify the caching mode of a data disk

PS C:\> $VM = Get-AzureRMVM -ResourceGroupName "ResourceGroup11" -VMName "ContosoVM07"
PS C:\> Set-AzureRmVMDataDisk -VM $VM -Name "DataDisk01" -Caching ReadWrite | Update-AzureRmVM

The first command gets the virtual machine named ContosoVM07 by using Get-AzureRmVM. The command stores it in the $VM variable. The second command modifies the caching mode for the data disk named DataDisk01 on the virtual machine in $VM. The command passes the result to the Update-AzureRmVM cmdlet, which implements your changes. A change to the cashing mode causes the virtual machine to restart.

Parameters

-Caching

Specifies the caching mode of the disk. The acceptable values for this parameter are:

  • ReadOnly
  • ReadWrite The default value is ReadWrite. Changing this value causes the virtual machine to restart. This setting affects the consistency and performance of the disk.
Type:Nullable<T>[CachingTypes]
Accepted values:None, ReadOnly, ReadWrite
Position:2
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-DefaultProfile

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

Type:IAzureContextContainer
Aliases:AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-DiskSizeInGB

Specifies the size, in gigabytes, for the data disk.

Type:Nullable<T>[Int32]
Position:3
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Lun

Specifies the logical unit number (LUN) of the data disk that this cmdlet modifies.

Type:Nullable<T>[Int32]
Position:1
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Name

Specifies the name of the data disk that this cmdlet modifies.

Type:String
Position:1
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-StorageAccountType

The virtual machine managed disk's account type.

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

-VM

Specifies the virtual machine for which this cmdlet modifies a data disk. To obtain a virtual machine object, use the Get-AzureRmVM cmdlet.

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

-WriteAccelerator

Specifies whether WriteAccelerator should be enabled or disabled on the data disk.

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

Inputs

PSVirtualMachine

String

Nullable<T>[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

Nullable<T>[[Microsoft.Azure.Management.Compute.Models.CachingTypes, Microsoft.Azure.Management.Compute, Version=21.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]

Outputs

PSVirtualMachine