Edit

Share via


Set-AzVMDataDisk

Modifies properties of a virtual machine data disk.

Syntax

ChangeWithName

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

ChangeWithLun

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

Description

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

Examples

Example 1: Modify the caching mode of a data disk

$VM = Get-AzVM -ResourceGroupName "ResourceGroup11" -VMName "ContosoVM07"
Set-AzVMDataDisk -VM $VM -Name "DataDisk01" -Caching ReadWrite | Update-AzVM

The first command gets the virtual machine named ContosoVM07 by using Get-AzVM. 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-AzVM cmdlet, which implements your changes. A change to the cashing mode causes the virtual machine to restart.

Example 2

Modifies properties of a virtual machine data disk. (autogenerated)

Set-AzVMDataDisk -Caching None -Lun 1 -VM <PSVirtualMachine>

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.

Parameter properties

Type:

Nullable<T>[CachingTypes]

Default value:None
Accepted values:None, ReadOnly, ReadWrite
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:2
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-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

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DiskEncryptionSetId

Specifies the resource Id of customer managed disk encryption set. This can only be specified for managed disk.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DiskSizeInGB

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

Parameter properties

Type:

Nullable<T>[Int32]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:3
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Lun

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

Parameter properties

Type:

Nullable<T>[Int32]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ChangeWithLun
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Name

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

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ChangeWithName
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-StorageAccountType

The virtual machine managed disk's account type.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-VM

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

Parameter properties

Type:PSVirtualMachine
Default value:None
Supports wildcards:False
DontShow:False
Aliases:VMProfile

Parameter sets

(All)
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

-WriteAccelerator

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

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

String

Nullable<T>

Nullable<T>

Outputs

PSVirtualMachine