Add-AzureDataDisk

Adds a data disk to a virtual machine.

Note

The cmdlets referenced in this documentation are for managing legacy Azure resources that use Azure Service Manager (ASM) APIs. This legacy PowerShell module isn't recommended when creating new resources since ASM is scheduled for retirement. For more information, see Azure Service Manager retirement.

The Az PowerShell module is the recommended PowerShell module for managing Azure Resource Manager (ARM) resources with PowerShell.

Syntax

Add-AzureDataDisk
   [-CreateNew]
   [-DiskSizeInGB] <Int32>
   [-DiskLabel] <String>
   [-LUN] <Int32>
   [-MediaLocation <String>]
   [-HostCaching <String>]
   -VM <IPersistentVM>
   [-Profile <AzureSMProfile>]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [<CommonParameters>]
Add-AzureDataDisk
   [-Import]
   [-DiskName] <String>
   [-LUN] <Int32>
   [-HostCaching <String>]
   -VM <IPersistentVM>
   [-Profile <AzureSMProfile>]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [<CommonParameters>]
Add-AzureDataDisk
   [-ImportFrom]
   [-DiskLabel] <String>
   [-LUN] <Int32>
   -MediaLocation <String>
   [-HostCaching <String>]
   -VM <IPersistentVM>
   [-Profile <AzureSMProfile>]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [<CommonParameters>]

Description

The Add-AzureDataDisk cmdlet adds a new or existing data disk to an Azure virtual machine object. Use the CreateNew parameter to create a new data disk that has a specified size and label. Use the Import parameter to attach an existing disk from the image repository. Use the ImportFrom parameter to attach an existing disk from a blob in a storage account. You can specify the host-cache mode of the attached data disk.

Examples

Example 1: Import a data disk from the repository

PS C:\> Get-AzureVM "ContosoService" -Name "VirtualMachine07" | Add-AzureDataDisk -Import -DiskName "Disk68" -LUN 0 | Update-AzureVM

This command gets a virtual machine object for the virtual machine named VirtualMachine07 in the ContosoService cloud service by using the Get-AzureVM cmdlet. The command passes it to the current cmdlet by using the pipeline operator. That command attaches an existing data disk from the repository to the virtual machine. The data disk has a LUN of 0. The command updates the virtual machine to reflect your changes by using the Update-AzureVM cmdlet.

Example 2: Add a new data disk

PS C:\> Get-AzureVM "ContosoService" -Name "VirtualMachine08" | Add-AzureDataDisk -CreateNew -DiskSizeInGB 128 -DiskLabel "main" -LUN 0 | Update-AzureVM

This command gets a virtual machine object for the virtual machine named VirtualMachine08. The command passes it to the current cmdlet. That command attaches a new data disk named MyNewDisk.vhd. The cmdlet creates the disk in the vhds container in the default storage account of the current subscription. The command updates the virtual machine to reflect your changes.

Example 3: Add a data disk from a specified location

PS C:\> Get-AzureVM "ContosoService" -Name "Database" | Add-AzureDataDisk -ImportFrom -MediaLocation "https://contosostorage.blob.core.windows.net/container07/Disk14.vhd" -DiskLabel "main" -LUN 0 | Update-AzureVM

This command gets a virtual machine object for the virtual machine named Database. The command passes it to the current cmdlet. That command attaches an existing data disk named Disk14.vhd from the specified location. The command updates the virtual machine to reflect your changes.

Parameters

-CreateNew

Indicates that this cmdlet creates a data disk.

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

-DiskLabel

Specifies the disk label for a new data disk.

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

-DiskName

Specifies the name of a data disk in the disk repository.

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

-DiskSizeInGB

Specifies the logical disk size, in gigabytes, for a new data disk.

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

-HostCaching

Specifies the host level caching settings of the disk. Valid values are:

  • None
  • ReadOnly
  • ReadWrite
Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Import

Indicates that this cmdlet imports an existing data disk from the image repository.

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

-ImportFrom

Indicates that this cmdlet imports an existing data disk from a blob in a storage account.

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

-InformationAction

Specifies how this cmdlet responds to an information event.

The acceptable values for this parameter are:

  • Continue
  • Ignore
  • Inquire
  • SilentlyContinue
  • Stop
  • Suspend
Type:ActionPreference
Aliases:infa
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InformationVariable

Specifies an information variable.

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

-LUN

Specifies the logical unit number (LUN) for the data drive in the virtual machine. Valid values are: 0 through 15. Each data disk must have a unique LUN.

Type:Int32
Position:3
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-MediaLocation

Specifies the location of the blob in an Azure storage account where this cmdlet stores the data disk. If you do not specify a location, the cmdlet stores the data disk in the vhds container in the default storage account for the current subscription. If a vhds container does not exist, the cmdlet creates a vhds container.

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

-Profile

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

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

-VM

Specifies the virtual machine object to which this cmdlet attaches a data disk. To obtain a virtual machine object, use the Get-AzureVM cmdlet.

Type:IPersistentVM
Aliases:InputObject
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False