New-AzVMDataDisk
Creates a local data disk object for a virtual machine or a Vmss VM.
Syntax
NormalDiskParameterSetName (Default)
New-AzVMDataDisk
[-Lun] <Int32>
[-CreateOption] <String>
[-Name <String>]
[-Caching <CachingTypes>]
[-DiskSizeInGB <Int32>]
[-VhdUri <String>]
[-SourceImageUri <String>]
[-DiskEncryptionSetId <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
ManagedDiskParameterSetName
New-AzVMDataDisk
[-Lun] <Int32>
[-CreateOption] <String>
[-Name <String>]
[-Caching <CachingTypes>]
[-DiskSizeInGB <Int32>]
[-ManagedDiskId <String>]
[-StorageAccountType <String>]
[-DiskEncryptionSetId <String>]
[-WriteAccelerator]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
The New-AzVMDataDisk cmdlet creates a local data disk object for a virtual machine or a Vmss VM.
Examples
Example 1: Add a managed data disk to a Vmss VM.
$disk = Get-AzDisk -ResourceGroupName $rgname -DiskName $diskname0
$datadisk = New-AzVMDataDisk -Caching 'ReadOnly' -Lun 2 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk.Id
$VmssVM = Get-AzVmssVM -ResourceGroupName "myrg" -VMScaleSetName "myvmss" -InstanceId 0
Update-AzVmssVM -ResourceGroupName "myrg" -VMScaleSetName "myvmss" -InstanceId 0 -DataDisk $datadisk
The first command gets an existing managed disk.
The next command creates a data disk object with the managed disk.
The next command gets an existing Vmss VM given by the resource group name, the vmss name and the instance ID.
The final command updates the Vmss VM by adding a new data disk.
Example 2
Creates a local data disk object for a virtual machine or a Vmss VM. (autogenerated)
New-AzVMDataDisk -Caching None -CreateOption Attach -DiskSizeInGB 1 -Lun 2 -Name 'AgentPool01'
Parameters
-Caching
The virtual machine data disk's caching.
Parameter properties
Type: CachingTypes
Default value: None
Accepted values: None, ReadOnly, ReadWrite
Supports wildcards: False
DontShow: False
Parameter sets
(All)
Position: Named
Mandatory: False
Value from pipeline: False
Value from pipeline by property name: True
Value from remaining arguments: False
-CreateOption
The virtual machine data disk's create option.
Parameter properties
Type: String
Default value: None
Supports wildcards: False
DontShow: False
Parameter sets
(All)
Position: 1
Mandatory: True
Value from pipeline: False
Value from pipeline by property name: True
Value from remaining arguments: False
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.
Parameter properties
Type: IAzureContextContainer
Default value: None
Supports wildcards: False
DontShow: False
Aliases: AzContext, AzureRmContext, AzureCredential
Parameter sets
(All)
Position: Named
Mandatory: False
Value from pipeline: False
Value from pipeline by property name: False
Value from remaining arguments: False
-DiskEncryptionSetId
The virtual machine managed disk encryption set's Id.
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
-DiskSizeInGB
The virtual machine data disk's size in GB.
Parameter properties
Type: Nullable<T> [ Int32 ]
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: True
Value from remaining arguments: False
-Lun
The virtual machine data disk's Lun.
Parameter properties
Type: Int32
Default value: None
Supports wildcards: False
DontShow: False
Parameter sets
(All)
Position: 0
Mandatory: True
Value from pipeline: False
Value from pipeline by property name: True
Value from remaining arguments: False
-ManagedDiskId
The virtual machine managed disk's Id.
Parameter properties
Type: String
Default value: None
Supports wildcards: False
DontShow: False
Parameter sets
ManagedDiskParameterSetName
Position: Named
Mandatory: False
Value from pipeline: False
Value from pipeline by property name: True
Value from remaining arguments: False
-Name
The virtual machine data disk's name.
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: True
Value from remaining arguments: False
-SourceImageUri
The virtual machine OS disk's source image Uri.
Parameter properties
Type: String
Default value: None
Supports wildcards: False
DontShow: False
Aliases: SourceImage
Parameter sets
NormalDiskParameterSetName
Position: Named
Mandatory: False
Value from pipeline: False
Value from pipeline by property name: True
Value from remaining arguments: False
-StorageAccountType
The virtual machine managed disk's account type.
Parameter properties
Type: String
Default value: None
Supports wildcards: False
DontShow: False
Parameter sets
ManagedDiskParameterSetName
Position: Named
Mandatory: False
Value from pipeline: False
Value from pipeline by property name: True
Value from remaining arguments: False
-VhdUri
The virtual machine data disk's Vhd Uri.
Parameter properties
Type: String
Default value: None
Supports wildcards: False
DontShow: False
Parameter sets
NormalDiskParameterSetName
Position: Named
Mandatory: False
Value from pipeline: False
Value from pipeline by property name: True
Value from remaining arguments: False
-WriteAccelerator
Specifies whether WriteAccelerator should be enabled or disabled on a managed data disk.
Parameter properties
Type: SwitchParameter
Default value: None
Supports wildcards: False
DontShow: False
Parameter sets
ManagedDiskParameterSetName
Position: Named
Mandatory: False
Value from pipeline: False
Value from pipeline by property name: False
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 .
Outputs