host caching

Glenn Maxwell 10,146 Reputation points
2021-08-20T12:42:24.287+00:00

Hi All

I have a windows 2019 server hosted in Azure. I want to add additional drive to it. The server currently has operating system drive only.
I want to add additional drive using PowerShell. i am not sure what should be the default caching or recommended value to be set for additional drive. please guide me. if i dont mention caching what value will it take. in the below syntax i just put ReadOnly but i am not sure

$vmName = "Server01"
$disk_name = "_DataDrive"
$size = 100
$lun = 0
$vm = Get-AzVM -Nam $vmName
$rgName = $vm.ResourceGroupName
$location = $vm.location 
$storageType = 'Premium_LRS'
$dataDiskName = $vmName + $disk_name
$tags = $vm.Tags
$diskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Empty -DiskSizeGB $size -tag $Tags
$dataDisk1 = New-AzDisk -DiskName $dataDiskName -Disk $diskConfig -ResourceGroupName $rgName
$vm = Add-AzVMDataDisk -VM $vm -Name $dataDiskName -CreateOption Attach -ManagedDiskId $dataDisk1.Id -Lun $lun -Caching 'ReadOnly'
Update-AzVM -VM $vm -ResourceGroupName $rgName
Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,491 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,244 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,395 questions
0 comments No comments
{count} votes

Accepted answer
  1. Glenn Maxwell 10,146 Reputation points
    2021-08-20T12:54:03.7+00:00

    As per the below article ReadWrite is the default value.

    https://learn.microsoft.com/en-us/powershell/module/az.compute/add-azvmdatadisk?view=azps-6.3.0&viewFallbackFrom=azps-6.0.0#parameters

    i believe the below syntax should work for me.

     $vmName = "Server01"  
     $disk_name = "_DataDrive"  
     $size = 100  
     $lun = 0  
     $vm = Get-AzVM -Nam $vmName  
     $rgName = $vm.ResourceGroupName  
     $location = $vm.location   
     $storageType = 'Premium_LRS'  
     $dataDiskName = $vmName + $disk_name  
     $tags = $vm.Tags  
     $diskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Empty -DiskSizeGB $size -tag $Tags  
     $dataDisk1 = New-AzDisk -DiskName $dataDiskName -Disk $diskConfig -ResourceGroupName $rgName  
     $vm = Add-AzVMDataDisk -VM $vm -Name $dataDiskName -CreateOption Attach -ManagedDiskId $dataDisk1.Id -Lun $lun -Caching 'ReadWrite'  
     Update-AzVM -VM $vm -ResourceGroupName $rgName  
    
    0 comments No comments

0 additional answers

Sort by: Most helpful