Edit

Share via


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

CreateNew (Default)

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

Import

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

ImportFrom

Add-AzureDataDisk
    [-DiskLabel] <String>
    [-LUN] <Int32>
    -MediaLocation <String>
    -VM <IPersistentVM>
    [-ImportFrom]
    [-HostCaching <String>]
    [-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.

Parameter properties

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

Parameter sets

CreateNew
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DiskLabel

Specifies the disk label for a new data disk.

Parameter properties

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

Parameter sets

CreateNew
Position:2
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
ImportFrom
Position:2
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DiskName

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

Parameter properties

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

Parameter sets

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

-DiskSizeInGB

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

Parameter properties

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

Parameter sets

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

-HostCaching

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

  • None
  • ReadOnly
  • ReadWrite

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

-Import

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

Parameter properties

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

Parameter sets

Import
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ImportFrom

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

Parameter properties

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

Parameter sets

ImportFrom
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-InformationAction

Specifies how this cmdlet responds to an information event.

The acceptable values for this parameter are:

  • Continue
  • Ignore
  • Inquire
  • SilentlyContinue
  • Stop
  • Suspend

Parameter properties

Type:ActionPreference
Default value:None
Supports wildcards:False
DontShow:False
Aliases:infa

Parameter sets

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

-InformationVariable

Specifies an information variable.

Parameter properties

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

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments: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.

Parameter properties

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

Parameter sets

(All)
Position:3
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments: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.

Parameter properties

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

Parameter sets

CreateNew
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments: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.

Parameter properties

Type:AzureSMProfile
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

-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.

Parameter properties

Type:IPersistentVM
Default value:None
Supports wildcards:False
DontShow:False
Aliases:InputObject

Parameter sets

(All)
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
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.