Add-AzureVMDataDisk

Add-AzureVMDataDisk

Adds a data disk to a virtual machine.

Syntax

Parameter Set: Default
Add-AzureVMDataDisk [-VM] <PSVirtualMachine> [-Name] <String> [[-VhdUri] <String> ] [[-Caching] <String> {ReadOnly | ReadWrite} ] [-DiskSizeInGB] <Int32]> [[-Lun] <Int32]> ] [-CreateOption] <System.String> {empty | attach | fromImage} [[-SourceImageUri] <System.String> ] [-Profile <AzureProfile> ] [ <CommonParameters>]




Detailed Description

The Add-AzureVMDataDisk 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<String>

Specifies the caching mode of the disk. Valid values 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.


Aliases

none

Required?

false

Position?

4

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-CreateOption<System.String>

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

-- Attach
-- Empty
-- FromImage


Aliases

none

Required?

true

Position?

7

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-DiskSizeInGB<Int32]>

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


Aliases

none

Required?

true

Position?

5

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Lun<Int32]>

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


Aliases

none

Required?

false

Position?

6

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Name<String>

Specifies the name of the data disk to add.


Aliases

none

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

true(ByPropertyName)

Accept Wildcard Characters?

false

-Profile<AzureProfile>

Specifies the Azure profile from which this cmdlet reads. If you do not specify a profile, this cmdlet reads from the local default profile.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-SourceImageUri<System.String>

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


Aliases

SourceImage

Required?

false

Position?

8

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.


Aliases

none

Required?

false

Position?

3

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. To obtain a virtual machine object, use the Get-AzureVM cmdlet. Create a virtual machine object by using the New-AzureVMConfig cmdlet.


Aliases

VMProfile

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true(ByValue,ByPropertyName)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.

Examples

Example 1: Add data disks to a new virtual machine

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.


$VirtualMachine = New-AzureVMConfig -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-AzureVMDataDisk -VM $VirtualMachine -Name 'DataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $DataDiskVhdUri1 -CreateOption Empty
PS C:\> $VirtualMachine = Add-AzureVMDataDisk -VM $VirtualMachine -Name 'DataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $DataDiskVhdUri2 -CreateOption Empty
PS C:\> $VirtualMachine = Add-AzureVMDataDisk -VM $VirtualMachine -Name 'DataDisk3' -Caching 'ReadOnly' -DiskSizeInGB 12 -Lun 2 -VhdUri $DataDiskVhdUri3 -CreateOption Empty

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

The first command gets the virtual machine named VirtualMachine07 by using the Get-AzureVM 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.


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

Related topics

Show: