Expand virtual machines hard disk - automation

· 4 min read

Sometimes, at some customers’s place, with an infrastructure already in place (XenApp with PVS or XenDesktop VDI pooled with PVS) the D: drive is too small. The drive where you redirect Windows Event Logs, Logs (UPM for example and/or other applications – services) This is a drive where page file is often redirected as well and even memory dump file generated. PVS cache can also be on this drive :

Cache on device RAM with overflow on Hard Disk

When RAM is zero, the target device write cache is only written to the local disk. When RAM is not zero, the target device write cache is written to RAM first. When RAM is full, the least recently used block of data is written to the local Write Cache disk to accommodate newer data on RAM. The amount of RAM specified is the non-paged kernel memory that the target device consumes.

Cache on device Hard Disk

The cache on local HD is stored in a file on a secondary local hard drive of the device. It gets created as an invisible file in the root folder of the secondary local HD. The cache file size grows, as needed, but never gets larger than the original vDisk, and often not larger than the free space on the original vDisk. It is slower than RAM cache, but faster than Server cache and works in a HA environment.

The lack of space on this drive will bring some slowness in user’s session and this drive needs to be expanded a bit to get back a normal user experience.

To expand these disks two actions need to be done :

  • Expand the Virtual Machine hard disk – in this example vmware Virtual Machines
  • Expand the disk within the Operation System (Windows)

In addition to the following script, psexec tool (Microsoft Sysinternal) is used to execute remotely the diskpart command listed in a text file (diskpart.txt) which is upload to the Virtual Machines. Targeted Virtual Machines need to be powered on. Psexec.exe and Diskpart.txt needs to be in the same folder as the Powershell script, of course you can specify their path as it suits your need.

rescan
select volume 1
extend
exit

 

This script is using XenDesktop / XenApp command to list all the Virtual Machines with SessionSupport value equal to SingleSession, it means the VDI only in my case. If you want to check the lust of Virtual Machines you targeted you can use this command :

Get-BrokerMachine  -AdminAddress XenDesktopDeliveryControlerAddressFQDN -Filter "((SessionSupport -eq `"SingleSession`"))" -Skip 0 | Select-Object HostedMachineName

If you want to target a specific XenDesktop Delivery Group, then just adapt the previous line :

Get-BrokerMachine  -AdminAddress XenDesktopDeliveryControlerAddressFQDN -Filter "((SessionSupport -eq `"SingleSession`" -and DesktopGroupName -eq `"Name of the Delivery Group`"))" -Skip 0 | Select-Object HostedMachineName

 

Once you know the target, you can execute the following script.

Add-PSSnapin citrix*
Add-PSSnapin vmware*
 
$XDDC = "XDDCFDQN"
$vCenter = "vCenterFQDN"
$NewSizeGB = "12"
 
connect-viserver $vCenter
 
foreach ($list in (Get-BrokerMachine  -AdminAddress $XDDC -Filter "((SessionSupport -eq `"SingleSession`"))" -Skip 0 | Select-Object HostedMachineName)) {
 
get-vm $list.HostedMachineName | get-harddisk | where {$_.name -eq "Disk 1"} | set-harddisk -confirm:$false -capacityGB $NewSizeGB
 copy diskpart.txt $vmc$windowstemp
 psexec $vm diskpart /s C:windowstempdiskpart.txt
 }
 
disconnect-viserver -Confirm:$false

As usual, if you have a better idea ( I’m sure you do ! ) drop me an email, a tweet or comment to share with the community 🙂

Sources :

Understanding Write Cache in Provisioning Services Server

Psexec – Microsoft