Move the Azure temporary disk to a different drive letter on Windows Server

On occasion you may have a need to move the Azure temporary drive to a different drive letter. Azure by default is set to use the D drive. This drive letter configuration may conflict with existing scripts or company OS installation standards. I’ve created an ARM template that uses PowerShell DSC to allow you to move the drive letter. It performs the following steps:

1) Disables the Windows Page File and reboots the VM
2) Changes the drive letter from the D drive to a drive letter you specify in the ARM template parameters file
3) Re-enables the Windows page file and reboots the VM

This project is in GitHub here: To use it, modify the azuredeploy.parameters.json file with your vmName and your desired tempDriveLetter:

    "$schema": "",
    "contentVersion": "",
  "parameters": {
    "vmName": {
      "value": "<put_your_existing_vm_name_here>"
    "assetLocation": {
      "value": ""
    "tempDriveLetter": {
      "value": "Z"

Optionally, you can copy the DSC file to your own Azure storage account and modify the assetLocation parameter as well. Also, if you have an existing DSC extension you will have to remove it before deploying this.

If you are interested in how this works, here is the explanation (note: assuming you understand how PowerShell DSC works):

To disable the Windows page file, we use “gwmi win32_pagefilesetting” which uses WMI to first check if the page file is enabled or not. If it is, we use this script to delete it and restart the VM:

gwmi win32_pagefilesetting
$pf=gwmi win32_pagefilesetting
Restart-Computer –Force

Once the VM restarts, the PowerShell DSC module will then change the drive letter to your desired drive and then re-enable the page file and reboot:

Get-Partition -DriveLetter "D"| Set-Partition -NewDriveLetter $TempDriveLetter
$TempDriveLetter = $TempDriveLetter + ":"
$drive = Get-WmiObject -Class win32_volume -Filter “DriveLetter = '$TempDriveLetter'”
#re-enable page file on new Drive
$drive = Get-WmiObject -Class win32_volume -Filter “DriveLetter = '$TempDriveLetter'”
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{ Name = "$TempDriveLetter\pagefile.sys"; MaximumSize = 0; }

Restart-Computer -Force

Comments (5)

  1. Bill Keane says:

    Good stuff. Thanks for taking the time to post this.

  2. rick willemain says:

    Thank you kindly !

  3. Mike says:

    Trying to run this from an arm template while the machine is being provisioned results in the following error: WinRM firewall exception will not work since one of the network connection types on this machine is set to Public. Change the network connection type to either Domain or Private and try again.

    Any idea?

  4. Justin says:

    Would be cool if this worked on Server 2008R2.

Skip to main content