Skip to content

Instantly share code, notes, and snippets.

@mrik23
Last active August 6, 2017 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrik23/a835bf977e6b9c13440e36045e20478c to your computer and use it in GitHub Desktop.
Save mrik23/a835bf977e6b9c13440e36045e20478c to your computer and use it in GitHub Desktop.
PowerShell snippet to change the Host Caching option for the OS disk of an existing VM in Azure RM.
#Requires Azure PowerShell v2
#Check documentation https://docs.microsoft.com/en-us/powershell/azure/active-directory/install-adv2?view=azureadps-2.0
#Make sure AzureRM module is installed and loaded
Import-Module AzureRM
#Connect to Azure
Login-AzureRmAccount
#Get the current VM config
$vm = Get-AzureRmVM -ResourceGroupName "myRG" -VMName "myVM"
#Change the Caching option. Possible value None, Read, ReadWrite.
$vm.StorageProfile.OsDisk.Caching = "None"
#Update the VM config
Update-AzureRmVM -VM $vm -ResourceGroupName "myRG"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment