Skip to content

Latest commit

 

History

History
467 lines (376 loc) · 16.9 KB

File metadata and controls

467 lines (376 loc) · 16.9 KB
external help file Microsoft.Azure.PowerShell.Cmdlets.Compute.dll-Help.xml
Module Name Az.Compute
ms.assetid 169E6694-82CD-4FCB-AB3D-E8A74001B8DB
online version https://learn.microsoft.com/powershell/module/az.compute/add-azvmdatadisk
schema 2.0.0

Add-AzVMDataDisk

SYNOPSIS

Adds a data disk to a virtual machine.

SYNTAX

VmNormalDiskParameterSetName (Default)

Add-AzVMDataDisk [-VM] <PSVirtualMachine> [[-Name] <String>] [[-VhdUri] <String>] [[-Caching] <CachingTypes>]
 [[-DiskSizeInGB] <Int32>] [-Lun] <Int32> [-CreateOption] <String> [[-SourceImageUri] <String>]
 [-DiskEncryptionSetId <String>] [-DeleteOption <String>] [-SourceResourceId <String>]
 [-DiskIOPSReadWrite <Int64>] [-DiskMBpsReadWrite <Int64>] [-DefaultProfile <IAzureContextContainer>]
 [<CommonParameters>]

VmManagedDiskParameterSetName

Add-AzVMDataDisk [-VM] <PSVirtualMachine> [[-Name] <String>] [[-Caching] <CachingTypes>]
 [[-DiskSizeInGB] <Int32>] [-Lun] <Int32> [-CreateOption] <String> [[-ManagedDiskId] <String>]
 [[-StorageAccountType] <String>] [-DiskEncryptionSetId <String>] [-WriteAccelerator] [-DeleteOption <String>]
 [-SourceResourceId <String>] [-DiskIOPSReadWrite <Int64>] [-DiskMBpsReadWrite <Int64>]
 [-SecurityEncryptionType <String>] [-SecureVMDiskEncryptionSet <String>]
 [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]

DESCRIPTION

The Add-AzVMDataDisk cmdlet adds a data disk to a virtual machine. You can add a data disk when you create a virtual machine, or you can add a data disk to an existing virtual machine.

EXAMPLES

Example 1: Add data disks to a new virtual machine

$VirtualMachine = New-AzVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
$DataDiskVhdUri01 = "https://contoso.blob.core.windows.net/test/data1.vhd"
$DataDiskVhdUri02 = "https://contoso.blob.core.windows.net/test/data2.vhd"
$DataDiskVhdUri03 = "https://contoso.blob.core.windows.net/test/data3.vhd"
$VirtualMachine = Add-AzVMDataDisk -VM $VirtualMachine -Name 'DataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $DataDiskVhdUri01 -CreateOption Empty
$VirtualMachine = Add-AzVMDataDisk -VM $VirtualMachine -Name 'DataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $DataDiskVhdUri02 -CreateOption Empty
$VirtualMachine = Add-AzVMDataDisk -VM $VirtualMachine -Name 'DataDisk3' -Caching 'ReadOnly' -DiskSizeInGB 12 -Lun 2 -VhdUri $DataDiskVhdUri03 -CreateOption Empty

The first 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 next three commands assign paths of three data disks to the $DataDiskVhdUri01, $DataDiskVhdUri02, and $DataDiskVhdUri03 variables. This approach is only for readability of the following commands. The final three commands each adds a data disk to the virtual machine stored in $VirtualMachine. The command specifies the name and location for the disk, and other properties of the disk. The URI of each disk is stored in $DataDiskVhdUri01, $DataDiskVhdUri02, and $DataDiskVhdUri03.

Example 2: Add a data disk to an existing virtual machine

$VirtualMachine = Get-AzVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
Add-AzVMDataDisk -VM $VirtualMachine -Name "disk1" -VhdUri "https://contoso.blob.core.windows.net/vhds/diskstandard03.vhd" -LUN 0 -Caching ReadOnly -DiskSizeinGB 1 -CreateOption Empty
Update-AzVM -ResourceGroupName "ResourceGroup11" -VM $VirtualMachine

The first command gets the virtual machine named VirtualMachine07 by using the Get-AzVM cmdlet. The command stores the virtual machine in the $VirtualMachine variable. The second command adds a data disk to the virtual machine stored in $VirtualMachine. The final command updates the state of the virtual machine stored in $VirtualMachine in ResourceGroup11.

Example 3: Add a data disk to a new virtual machine from a generalized user image

$VirtualMachine = New-AzVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
$DataImageUri = "https://contoso.blob.core.windows.net/system/Microsoft.Compute/Images/captured/dataimage.vhd"
$DataDiskUri = "https://contoso.blob.core.windows.net/test/datadisk.vhd"
$VirtualMachine = Add-AzVMDataDisk -VM $VirtualMachine -Name "disk1" -SourceImageUri $DataImageUri -VhdUri $DataDiskUri -Lun 0 -DiskSizeinGB 10 -CreateOption FromImage

The first 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 next two commands assign paths for the data image and data disks to the $DataImageUri and $DataDiskUri variables respectively. This approach is used to improve the readability of the following commands. The final commands adds a data disk to the virtual machine stored in $VirtualMachine. The command specifies the name and location for the disk and other properties of the disk.

Example 4: Add data disks to a new virtual machine from a specialized user image

$VirtualMachine = New-AzVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
$DataDiskUri = "https://contoso.blob.core.windows.net/test/datadisk.vhd"
$VirtualMachine = Add-AzVMDataDisk -VM $VirtualMachine -Name "dd1" -VhdUri $DataDiskUri -Lun 0 -DiskSizeinGB 10 -CreateOption Attach

The first 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 next commands assigns paths of the data disk to the $DataDiskUri variable. This approach is used to improve the readability of the following commands. The final command add a data disk to the virtual machine stored in $VirtualMachine. The command specifies the name and location for the disk, and other properties of the disk.

Example 5: Add an UltraSSD data disk with custom IOPS and throughput

$VirtualMachine = New-AzVMConfig -VMName "VirtualMachine07" -VMSize "Standard_D2s_v3"
$VirtualMachine = Add-AzVMDataDisk -VM $VirtualMachine -Name "UltraData1" -Lun 0 -CreateOption 'Empty' -DiskSizeInGB 10 -Caching 'None' -StorageAccountType 'UltraSSD_LRS' -DiskIOPSReadWrite 5000 -DiskMBpsReadWrite 200

The first 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 second command adds an UltraSSD data disk with custom IOPS (Input/Output Operations Per Second) set to 5000 and throughput set to 200 MB per second. These parameters allow fine-tuning of disk performance for UltraSSD_LRS and PremiumV2_LRS storage account types during implicit disk creation.

Example 6: Add a confidential data disk with SecurityEncryptionType

$VirtualMachine = New-AzVMConfig -VMName "VirtualMachine07" -VMSize "Standard_DC2as_v5"
$managedDiskId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myRG/providers/Microsoft.Compute/disks/myDataDisk"
$VirtualMachine = Add-AzVMDataDisk -VM $VirtualMachine -Name "ConfidentialDataDisk1" -Lun 0 -CreateOption 'Attach' -ManagedDiskId $managedDiskId -StorageAccountType 'Premium_LRS' -SecurityEncryptionType 'DiskWithVMGuestState' -SecureVMDiskEncryptionSet "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myRG/providers/Microsoft.Compute/diskEncryptionSets/myDES"

The first 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 second command adds a confidential data disk encrypted with the VMGuest state using a customer-managed key (CMK) via a Disk Encryption Set (DES). The SecurityEncryptionType parameter set to 'DiskWithVMGuestState' enables confidential disk encryption that binds the disk encryption keys to the VM's TPM (Trusted Platform Module). The SecureVMDiskEncryptionSet parameter specifies the ARM resource ID of the Disk Encryption Set created with the ConfidentialVmEncryptedWithCustomerKey encryption type. It is recommended to use this together with SecurityEncryptionType set to 'DiskWithVMGuestState'.

PARAMETERS

-Caching

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

  • ReadOnly
  • ReadWrite
  • None 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: Microsoft.Azure.Management.Compute.Models.CachingTypes
Parameter Sets: (All)
Aliases:
Accepted values: None, ReadOnly, ReadWrite

Required: False
Position: 3
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-CreateOption

Specifies whether this cmdlet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. The acceptable values for this parameter 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. The VhdUri is all that is needed in order to tell the Azure platform the location of the virtual hard disk (VHD) to attach as a data disk to the virtual machine.
  • Empty. Specify this to create an empty data disk.
  • FromImage. Specify this option to create a virtual machine from a generalized image or disk. When you specify this option, you must specify the SourceImageUri parameter also in order to tell the Azure platform the location of the VHD to attach as a data disk. The VhdUri parameter is used as the location identifying where the data disk VHD will be stored when it is used by the virtual machine.
  • Empty. This value is used when creating an empty data disk.
  • Copy. This value is used to create a data disk from a snapshot or another disk. Restore: This value is used to create a data disk from a disk restore point.
Type: System.String
Parameter Sets: (All)
Aliases:

Required: True
Position: 6
Default value: None
Accept pipeline input: True (ByPropertyName)
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
Parameter Sets: (All)
Aliases: AzContext, AzureRmContext, AzureCredential

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

-DeleteOption

Data Disk Delete Option. Specifies what action to perform on the disk after VM deletion. Options are: Detach, Delete.

Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-DiskEncryptionSetId

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

Type: System.String
Parameter Sets: (All)
Aliases:

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

-DiskSizeInGB

Specifies the size, in gigabytes, of an empty disk to attach to a virtual machine.

Type: System.Nullable`1[System.Int32]
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Lun

Specifies the logical unit number (LUN) for a data disk.

Type: System.Nullable`1[System.Int32]
Parameter Sets: (All)
Aliases:

Required: True
Position: 5
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-ManagedDiskId

Specifies the ID of a managed disk.

Type: System.String
Parameter Sets: VmManagedDiskParameterSetName
Aliases:

Required: False
Position: 8
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Name

Specifies the name of the data disk to add.

Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-SourceImageUri

Specifies the source URI of the disk that this cmdlet attaches.

Type: System.String
Parameter Sets: VmNormalDiskParameterSetName
Aliases: SourceImage

Required: False
Position: 7
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-SourceResourceId

ARM ID of snapshot or disk restore point from which to create a disk.

Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-StorageAccountType

Specifies the storage account type of managed disk.

Type: System.String
Parameter Sets: VmManagedDiskParameterSetName
Aliases:

Required: False
Position: 9
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-VhdUri

Specifies the Uniform Resource Identifier (URI) for the virtual hard disk (VHD) file to create when a platform image or user image is used. This cmdlet copies the image binary large object (blob) to this location. This is the location from which to start the virtual machine.

Type: System.String
Parameter Sets: VmNormalDiskParameterSetName
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-VM

Specifies the local virtual machine object to which to add a data disk. You can use the Get-AzVM cmdlet to obtain a virtual machine object. You can use the New-AzVMConfig cmdlet to create a virtual machine object.

Type: Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine
Parameter Sets: (All)
Aliases: VMProfile

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False

-WriteAccelerator

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

Type: System.Management.Automation.SwitchParameter
Parameter Sets: VmManagedDiskParameterSetName
Aliases:

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

-DiskIOPSReadWrite

Specifies the Read-Write IOPS (Input/Output Operations Per Second) for the disk when StorageAccountType is UltraSSD_LRS or PremiumV2_LRS.

Type: System.Nullable`1[System.Int64]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-DiskMBpsReadWrite

Specifies the bandwidth in MB per second for the disk when StorageAccountType is UltraSSD_LRS or PremiumV2_LRS.

Type: System.Nullable`1[System.Int64]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-SecurityEncryptionType

Sets the SecurityEncryptionType value on the managed disk of the data disk. Possible values include: DiskWithVMGuestState, VMGuestStateOnly, NonPersistedTPM. This parameter can only be used with managed disks.

Type: System.String
Parameter Sets: VmManagedDiskParameterSetName
Aliases:
Accepted values: DiskWithVMGuestState, VMGuestStateOnly, NonPersistedTPM

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-SecureVMDiskEncryptionSet

ARM Resource ID for the Disk Encryption Set (DES) to use for enabling confidential disk encryption for the managed data disk. This parameter can only be used with managed disks. It is recommended to set SecurityEncryptionType to DiskWithVMGuestState when using this parameter.

Type: System.String
Parameter Sets: VmManagedDiskParameterSetName
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine

System.String

Microsoft.Azure.Management.Compute.Models.CachingTypes

System.Nullable`1[[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]

OUTPUTS

Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine

Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSetVM

NOTES

RELATED LINKS

Remove-AzVMDataDisk

Get-AzVM

New-AzVMConfig