< Back
Add-AzureRmVMDataDisk
Post
NAME Add-AzureRmVMDataDisk
SYNOPSIS
Adds a data disk to a virtual machine.
SYNTAX
Add-AzureRmVMDataDisk [-VM] <PSVirtualMachine> [[-Name] <String>] [[-VhdUri] <String>] [[-Caching] {None | ReadOnly | ReadWrite}] [[-DiskSizeInGB]
<Int32>] [-Lun] <Int32> [-CreateOption] <String> [[-SourceImageUri] <String>] [[-ManagedDiskId] <String>] [[-StorageAccountType] <String>]
[-DefaultProfile <IAzureContextContainer>] [-WriteAccelerator] [<CommonParameters>]
DESCRIPTION
The Add-AzureRmVMDataDisk 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.
PARAMETERS
-Caching <CachingTypes>
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.
Required? false
Position? 3
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-CreateOption <String>
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.
Required? true
Position? 6
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-DefaultProfile <IAzureContextContainer>
The credentials, account, tenant, and subscription used for communication with azure.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-DiskSizeInGB <Int32>
Specifies the size, in gigabytes, of an empty disk to attach to a virtual machine.
Required? false
Position? 4
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-Lun <Int32>
Specifies the logical unit number (LUN) for a data disk.
Required? true
Position? 5
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-ManagedDiskId <String>
Specifies the ID of a managed disk.
Required? false
Position? 8
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-Name <String>
Specifies the name of the data disk to add.
Required? false
Position? 1
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-SourceImageUri <String>
Specifies the source URI of the disk that this cmdlet attaches.
Required? false
Position? 7
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-StorageAccountType <String>
Specifies the storage account type of managed disk.
Required? false
Position? 9
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-VhdUri <String>
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.
Required? false
Position? 2
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-VM <PSVirtualMachine>
Specifies the local virtual machine object to which to add a data disk. You can use the Get-AzureRmVM cmdlet to obtain a virtual machine
object. You can use the New-AzureRmVMConfig cmdlet to create a virtual machine object.
Required? true
Position? 0
Default value None
Accept pipeline input? True (ByPropertyName, ByValue)
Accept wildcard characters? false
-WriteAccelerator [<SwitchParameter>]
Specifies whether WriteAccelerator should be enabled or disabled on the data disk.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
PSVirtualMachine
Parameter 'VM' accepts value of type 'PSVirtualMachine' from the pipeline
OUTPUTS
Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine
NOTES
Example 1: Add data disks to a new virtual machine
PS C:\\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
PS C:\\> $DataDiskVhdUri01 = "https://contoso.blob.core.windows.net/test/data1.vhd"
PS C:\\> $DataDiskVhdUri02 = "https://contoso.blob.core.windows.net/test/data2.vhd"
PS C:\\> $DataDiskVhdUri03 = "https://contoso.blob.core.windows.net/test/data3.vhd"
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -VM $VirtualMachine -Name 'DataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri
$DataDiskVhdUri01 -CreateOption Empty
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -VM $VirtualMachine -Name 'DataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri
$DataDiskVhdUri02 -CreateOption Empty
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -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
PS C:\\> $VirtualMachine = Get-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
PS C:\\> Add-AzureRmVMDataDisk -VM $VirtualMachine -Name "disk1" -VhdUri "https://contoso.blob.core.windows.net/v ... dard03.vhd" -LUN 0
-Caching ReadOnly -DiskSizeinGB 1 -CreateOption Empty
PS C:\\> Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -VM $VirtualMachine
The first command gets the virtual machine named VirtualMachine07 by using the Get-AzureRmVM (./Get-AzureRmVM.md)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
PS C:\\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
PS C:\\> $DataImageUri = "https://contoso.blob.core.windows.net/s ... aimage.vhd"
PS C:\\> $DataDiskUri = "https://contoso.blob.core.windows.net/test/datadisk.vhd"
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -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
PS C:\\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
PS C:\\> $DataDiskUri = "https://contoso.blob.core.windows.net/test/datadisk.vhd"
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -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.
RELATED LINKS
Online Version: https://docs.microsoft.com/en-us/powers ... vmdatadisk
Remove-AzureRmVMDataDisk
Get-AzureRmVmssDiskEncryption
New-AzureRmVMConfig
SYNOPSIS
Adds a data disk to a virtual machine.
SYNTAX
Add-AzureRmVMDataDisk [-VM] <PSVirtualMachine> [[-Name] <String>] [[-VhdUri] <String>] [[-Caching] {None | ReadOnly | ReadWrite}] [[-DiskSizeInGB]
<Int32>] [-Lun] <Int32> [-CreateOption] <String> [[-SourceImageUri] <String>] [[-ManagedDiskId] <String>] [[-StorageAccountType] <String>]
[-DefaultProfile <IAzureContextContainer>] [-WriteAccelerator] [<CommonParameters>]
DESCRIPTION
The Add-AzureRmVMDataDisk 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.
PARAMETERS
-Caching <CachingTypes>
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.
Required? false
Position? 3
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-CreateOption <String>
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.
Required? true
Position? 6
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-DefaultProfile <IAzureContextContainer>
The credentials, account, tenant, and subscription used for communication with azure.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-DiskSizeInGB <Int32>
Specifies the size, in gigabytes, of an empty disk to attach to a virtual machine.
Required? false
Position? 4
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-Lun <Int32>
Specifies the logical unit number (LUN) for a data disk.
Required? true
Position? 5
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-ManagedDiskId <String>
Specifies the ID of a managed disk.
Required? false
Position? 8
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-Name <String>
Specifies the name of the data disk to add.
Required? false
Position? 1
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-SourceImageUri <String>
Specifies the source URI of the disk that this cmdlet attaches.
Required? false
Position? 7
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-StorageAccountType <String>
Specifies the storage account type of managed disk.
Required? false
Position? 9
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-VhdUri <String>
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.
Required? false
Position? 2
Default value None
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
-VM <PSVirtualMachine>
Specifies the local virtual machine object to which to add a data disk. You can use the Get-AzureRmVM cmdlet to obtain a virtual machine
object. You can use the New-AzureRmVMConfig cmdlet to create a virtual machine object.
Required? true
Position? 0
Default value None
Accept pipeline input? True (ByPropertyName, ByValue)
Accept wildcard characters? false
-WriteAccelerator [<SwitchParameter>]
Specifies whether WriteAccelerator should be enabled or disabled on the data disk.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
PSVirtualMachine
Parameter 'VM' accepts value of type 'PSVirtualMachine' from the pipeline
OUTPUTS
Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine
NOTES
Example 1: Add data disks to a new virtual machine
PS C:\\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
PS C:\\> $DataDiskVhdUri01 = "https://contoso.blob.core.windows.net/test/data1.vhd"
PS C:\\> $DataDiskVhdUri02 = "https://contoso.blob.core.windows.net/test/data2.vhd"
PS C:\\> $DataDiskVhdUri03 = "https://contoso.blob.core.windows.net/test/data3.vhd"
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -VM $VirtualMachine -Name 'DataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri
$DataDiskVhdUri01 -CreateOption Empty
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -VM $VirtualMachine -Name 'DataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri
$DataDiskVhdUri02 -CreateOption Empty
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -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
PS C:\\> $VirtualMachine = Get-AzureRmVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
PS C:\\> Add-AzureRmVMDataDisk -VM $VirtualMachine -Name "disk1" -VhdUri "https://contoso.blob.core.windows.net/v ... dard03.vhd" -LUN 0
-Caching ReadOnly -DiskSizeinGB 1 -CreateOption Empty
PS C:\\> Update-AzureRmVM -ResourceGroupName "ResourceGroup11" -VM $VirtualMachine
The first command gets the virtual machine named VirtualMachine07 by using the Get-AzureRmVM (./Get-AzureRmVM.md)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
PS C:\\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
PS C:\\> $DataImageUri = "https://contoso.blob.core.windows.net/s ... aimage.vhd"
PS C:\\> $DataDiskUri = "https://contoso.blob.core.windows.net/test/datadisk.vhd"
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -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
PS C:\\> $VirtualMachine = New-AzureRmVMConfig -VMName "VirtualMachine07" -VMSize "Standard_A1"
PS C:\\> $DataDiskUri = "https://contoso.blob.core.windows.net/test/datadisk.vhd"
PS C:\\> $VirtualMachine = Add-AzureRmVMDataDisk -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.
RELATED LINKS
Online Version: https://docs.microsoft.com/en-us/powers ... vmdatadisk
Remove-AzureRmVMDataDisk
Get-AzureRmVmssDiskEncryption
New-AzureRmVMConfig