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 (6)

  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.

  5. Hasan Jamil says:

    I have a script that builds a VM in Azure. It already has extension added to do a domain join. I’ll like to know if I can add this extension in below format. I can’t seem to get it right. It keeps getting errors. Any help would be appreciated.

    #========================Change Temporary Drive Letter===========================#

    $PublicSettings = ‘{“ModulesURL”:””, “configurationFunction”: “MoveAzureTempDrive.ps1\\MoveAzureTempDrive”, “Properties”: {“MachineName”: $VMname} }’

    Set-AzureRmVMExtension -ExtensionName “DSC” -ResourceGroupName myVMResourceGroup -VMName $vmName `
    -Publisher “Microsoft.Powershell” -ExtensionType “DSC” -TypeHandlerVersion 2.19 `
    -SettingString $PublicSettings -Location $VMResourceGroupLocation

Skip to main content