VMware Horizon – Preparing a Gold Master VM for Cloning

As a follow up to an older post,  Prepare Windows 7 Gold Master Virtual Machine for Cloning, below is a quick batch script that I use to prepare my Windows gold VMs just before creating a snapshot and recomposing my pools.

I’ve added a few commands for my environment, but credit to this blog for the framework:

This script has been tested on the following platforms:

  • Windows 10 Enterprise 1511
  • Windows 10 Enterprise 1607
  • Windows 10 Enterprise 1607 LTSB
  • Windows 10 Enterprise 1703

I have not tested it on Windows 7/8/8.1, but I imagine it will work fine on those platforms as well.

In summary, when executed the script will:

  1. Execute all queued .NET framework items
  2. Disable the Windows Update Service
  3. Configures the AppVolumes Service for automatic start, if applicable
  4. Delete all shadow copies
  5. Delete cached Windows Update downloads
  6. Delete hidden install files
  7. Delete prefetch files
  8. Run Disk Cleanup
  9. Defragment the disk
  10. Rearm Office 2016 activation, if applicable
  11. Clear the Windows Event Logs
  12. Release the currently assigned IP address
  13. Flush the local DNS cache
  14. Shut down the VM

Script code:

REM Copy this code into a blank txt file and then rename the file to VMCleanup.bat
REM Copy VMCleanup.bat to your Gold Master VM and run as an admin just before creating a snapshot
REM *****************************************************
REM Execute queued .NET Framework items
C:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe executeQueuedItems
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\ngen.exe executeQueuedItems
REM *****************************************************
REM Stop and Disable the Windows Update Service
sc stop wuauserv
sc config wuauserv start= disabled
REM *****************************************************
REM Set AppVolumes Service to automatic start
sc config svservice start= auto
REM *****************************************************
REM Delete shadow copies
vssadmin delete shadows /All /Quiet
REM *****************************************************
REM Delete all cached Windows Update downloads
del c:\Windows\SoftwareDistribution\Download\*.* /f /s /q
REM *****************************************************
REM Delete hidden install files
del %windir%\$NT* /f /s /q /a:h
REM *****************************************************
REM Delete prefetch files
del c:\Windows\Prefetch\*.* /f /s /q
REM *****************************************************
REM Run Disk Cleanup. Runc:\windows\system32\cleanmgr /sageset:1 and check
REM desired options before running
c:\windows\system32\cleanmgr /sagerun:1
REM *****************************************************
REM Defragment the disk
sc config defragsvc start= auto
net start defragsvc
defrag c: /U /V
net stop defragsvc
sc config defragsvc start = disabled
REM *****************************************************
REM Rearm Microsoft Office 2016 activation
"C:\Program Files (x86)\Microsoft Office\Office16\OSPPREARM.exe"
REM *****************************************************
REM Clear Windows Event Logs
wevtutil el 1>a.txt
for /f %%x in (a.txt) do wevtutil cl %%x
del a.txt
REM *****************************************************
REM Release IP address
ipconfig /release
REM *****************************************************
REM Flush DNS cache
ipconfig /flushdns
REM *****************************************************
REM Shutdown the VM
shutdown -s -f -t 15


Disclaimer: Scripts on this blog are provided as-is and I offer not support for them. All scripts were written for and tested in the specific environment for which they were intended for use, and are in no way guaranteed. Always test scripts in an isolated environment and please feel free to make modifications as needed. I also acknowledge that there may be alternate and/or more efficient ways to write these scripts and accomplish the same tasks, and I welcome suggestions and feedback.


Prepare Windows 7 Gold Master Virtual Machine for Cloning

I shared this link as part of my VMware Horizon View – Resource Dump post, but there is a section of it that I thought deserved special attention.

The full origional post is here if you wish to review it: VMware View 5.x – Windows 7 Golden Image

Specifically, the final step in the post contains very good information on how to “Clean up the machine”. I’ve adopted this process in my own environments to prepare Windows 7 gold master virtual machines for cloning, and I highly recommend it.

Important notes: These steps assume you’ve fully patched, installed all third-party software, made all necessary changes, and are fully prepared to finalize your gold master VM for deployment. These steps should be repeated every time changes are made to the gold master VM before creating a new snapshot and recomposing your desktop pools.

On your gold master virtual machine, perform the following to finalize it for deployment:

  1. Open an elevated command prompt
  2. Enter and run:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe executeQueuedItems

*Depending upon your OS version and .NET Framework versions installed, the exact folder containing ngen.exe may be different. I recommend that you verify this path prior to running these commands.

According to the referenced post, “This (command) will precompile all .NET assemblies which might still be queued”. If this is the first time this command has been run on this system you may see it run through a series of tasks that can take several minutes to complete, but it’s also normal to receive a simple “All compilation targets are up to date” message.

  1. If the OS is 64-bit, run the same command again but from the Framework64 folder.

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\ngen.exe executeQueuedItems

  1. Browse to and delete all contents of C:\Windows\SoftwareDistribution\Download
  2. Run the following to clear all of the system event logs:
    • wevtutil el >a.txt
    • for /f %x in (a.txt) do wevtutil cl %x
    • del a.txt
  1. Run Disk Cleanup on drive C: to remove unneeded files
  2. Defragment drive C:

*If you’ve followed VMware’s recommended optimizations for Windows 7, the Disk Defragmenter service is likely disabled. You will need to enable and start this service in order to defragment the disk, but be sure to disable it again before continuing.

  1. Release the IP address with ipconfig /release
  2. Flush the DNS cache with ipconfig /flushdns
  3. Shut down the VM and take a snapshot to use for cloning


VMware Horizon View – Cleanup Unused Replicas


Here is a good KB from VMware on how to find unused replca virtual machines so that they can be safely removed from vCenter.

Finding and removing unused replica virtual machines in VMware View (2009844)

From the article:

Finding and removing unused replicas

To find and remove unused replicas:
  1. In vCenter Server or the server where the composer is installed, stop the VMware View Composer service.Note: When this Service is down, no recompose, refresh, or provisioning operations occur. Use a convenient maintenance window.
  2. Click Start.
  3. Type Services.
  4. Press Enter.
  5. Click the VMware View Composer Service.
  6. Click Stop.
  7. Open a command prompt.
  8. Navigate to the View Composer install directory.
  9. Run the sviconfig.exe command with the FindUnusedReplica operation:

SviConfig.exe -operation=FindUnusedReplica -DsnName=<the name of the Composer database DSN> -Username=<the user name of Composer database owner> -Password=<the password of Composer database owner>

For example:

SviConfig.exe -operation=FindUnusedReplica -DsnName=ComposerDB -Username=sa -Password=secret


  1. If the command finds any unused replicas, they are listed in a new file created in the current directory ( unused-replica-*.txt).
  2. Unused replicas can be unprotected and moved to a unique folder with the parameter:


For example:

SviConfig.exe -operation=FindUnusedReplica -DsnName=ComposerDB -Username=sa -Password=secret -Move=trueNotes:Open a vSphere Client and connect to vCenter Server.


  • When using the move=true option, you will receive warning pop-ups. These are safe to ignore.
  • Note The UnusedViewComposerReplicaFolder is created automatically if it does not exist, and unused replicas are moved to this folder.
  1. Open a vSphere Client and connect to vCenter Server
  2. Click Inventory > VMs and Templates.
  3. Remove the replicas located in the UnusedViewComposerReplicaFolder.
  4. Start the VMware View Composer service.


VMware Horizon View – Performing Maintenance on or Replacing an ESX Host in a Cluster

I wanted to provide some information to help clarify the process for performing maintenance on an ESXi host in a vCenter cluster that has active virtual machines on it. My experience with this type of maintenance is limited to Horizon View virtual desktops, but it is likely also applicable to clusters hosting virtual servers.

Replacing an ESX host in a cluster that has View Composer linked-clone pool installed (1015292) 

“To replace a ESX host in a cluster with deployed View Desktops:
  1. Prepare the new ESX host outside the cluster, verify all datastores that are available to the old ESX hosts in the cluster are accessible to the new ESX host.
  2. Put the old ESX host in Maintenance Mode from the vCenter Server GUI.
  3. Ensure that you have selected the Move powered off and suspended virtual machines to other hosts in the cluster option.
  4. The running virtual machines migrate to other ESX hosts in the cluster, shutdown and suspended virtual machines and replicas are moved as well. The ESX host enters Maintenance Mode.Note: If the Replica virtual machine did not migrate then you need to unprotect it. For instructions on unprotecting the replica virtual machine, see Cannot remove source and replica virtual machines associated with View Composer desktop pools (1008704).
  5. Click the ESX host
  6. Click the Virtual Machines tab to verify that all virtual machines and replicas have been moved.
  7. In View 4.5 and later, if you have unprotected the replica virtual machine then you need to re-protect it. For more information, see Re-protecting a View replica virtual machine (2015006).
  8. Remove the ESX host in Maintenance Mode from the cluster.”

So, in summary, you should be able to put the host into Maintenance Mode and, if you have the cluster configured properly, the virtual desktops that are on it should be migrated over to other available hosts in the cluster.

If you have trouble putting an ESX/ESXi host into maintenance mode, check out ESXi/ESX host fails to go into maintenance mode (1036167).

One specific instance I’d like to note from personal experience: “If an ESXi/ESX host is a part of VMware High Availability (HA) or DRS cluster, check the Admission Control settings. You may have to disable this option if there are not enough resources to ensure fail over capacity. “

Which refers to this setting on your cluster:


For a more detailed explanation of Admission Control, see VMware HA Admission Control. The important parts pertaining to our topic of conversation:

“vCenter Server uses admission control to ensure that sufficient resources are available in a cluster to provide failover protection and to ensure that virtual machine resource reservations are respected.”

“Admission control imposes constraints on resource usage and any action that would violate these constraints is not permitted. Examples of actions that could be disallowed include the following:

  • Powering on a virtual machine.
  • Migrating a virtual machine onto a host or into a cluster or resource pool.
  • Increasing the CPU or memory reservation of a virtual machine.”

The second bullet is in bold because in order for a host to enter Maintenance Mode, all of the VMs assigned to that host must first be migrated to other available hosts in the cluster or powered off. If Admission Control is enabled on your cluster and during the VM migration process you violate the HA failover capacity check, the migrations will stop and you’ll likely get an error that the host could not enter maintenance mode.

At this point, you basically have two options; modify your Admission Control Policy settings to provide more failover capacity, or shutdown non-essential VMs on the host entering maintenance mode and disable Admission Control. Use caution doing either of these to avoid overwhelming your other hosts once the VMs have been migrated. If you disable AC, make sure you remember to enable it again once your maintenance has finished.

For some good resources on vSphere HA, check out Yellow-Bricks HS DeepDive and HA cluster configuration: Requirements and steps


VMware Horizon View – Resource Dump

When preparing for my VMware Horizon View deployment, I spent a lot of time (as you should too) searching, reading, and parsing through official documentation and expert guides. Most of what I found is easy enough to find with some simple Google searches but, in the interest of consolidation and to save you the trouble, what follows is a resource dump of what I found the most helpful.

VMware Horizon View Infrastructure Planning, Installation, and Administration

VMware Horizon View 5.3 Official Documentation Page

VMware Horizon View Architecture Planning

VMware Horizon View Installation

VMware Horizon View Administration

VMware Horizon View Security

VMware Horizon View Upgrades

Operating System Optimization for VDI

VMware Horizon View Optimization Guide for Windows 7 and Windows 8

VMware View 5 PCoIP Optimization Guide

VMware Horizon View 5.2 Performance and Best Practices

VMware OS Optimization Tool

My Top 10 VMware View Performance Tips

Turbo-charge View Video Performance

“For desktop VMs using VMXnet3 NICs, you can significantly improve the peak video playback performance of your View desktop by simply setting the following registry setting to the value recommended by Microsoft:”
HKLM\System\CurrentControlSet\Services\Afd\Parameters\FastSendDatagramThreshold to 1500

View Accelerated – 3D Graphics with Horizon View 5.2

“Registry change on the VM – [HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware SVGA DevTap]
“MaxAppFrameRate”=dword:00000000 – If it does not exist it defaults to 30. Set it to 0 to disable any frame cap.”

How to improve VMware View video performance

VMware KB 2010359

Method 1:
1. Power off the virtual machine using the vSphere Client.
2. Right-click the virtual machine and click Edit Settings.
3. Select the Options tab and under Advanced.
4. Click General.
5. Click Configuration Parameters and click Add Row
6. In the Name field enter mks.poll.headlessRates and in the Value field enter 1000 100 2.
7. Click OK.
8. Power on the virtual machine.

VMware View 5.x – Windows 7 Golden Image

“Video Card: Do not “Auto detect” (see VMware KB 1017380), set to 2 displays and 128 MB video memory”

“Remove he following components (features) from the OS (unless you really need them) and reboot VM:
• Games
• Media Features – Windows DVD Maker
• Media Features – Windows Media Center
• Print and Document Services – Internet Printing Client
• Print and Document Services – Windows Fax and Scan
• Tablet PC components
• Windows Gadget Platform”

Suggested changes to VMware View Optimization Script for Windows 7


VMware Horizon View Enable/Disable Teradici APEX PCoIP Offload Card Indicators

Here’s a good tip for testing your Teradici APEX PCoIP Offload cards to make sure they’re working properly in your VDI environment.

On your ESXi hosts, run the following commands to enable and disable an indicator that displays in the upper-left corner of your Virtual Desktops:

Enable indicator:

/opt/teradici/pcoip-ctrl -P “offload_indicator 1”

Disable indicator:

/opt/teradici/pcoip-ctrl -P “offload_indicator 0”

Red = PCoIP display is being offloaded

Blue = PCoIP not being offloaded

I found out about this when I stumbled upon the following VMAdmin UK blog post while researching how to properly configure the APEX cards. The blog has some other good information and tricks that are worth checking out if you’re interested.


VMware Horizon View Client Login Fails While Using the “Log in as current user” Option

You may run into this issue when attempting to use the “Log in as current user” option in the VMware Horizon View client. This option allows the user to log in to Horizon View using the currently logged on user’s credentials on Windows clients, so it avoids the need to authenticate twice.

To make a long story short, if “Log in as current user” isn’t working then make sure that your Connection Server’s SYSTEM account has “Access this computer from the network” rights on the local system. You can add it via Group Policy if necessary via the Computer Configuration\Policies\Windows Settings\Security Settings\Local Policies\User Rights Assignment\Access this computer from the network policy setting.

For more details, see VMware’s KB on the topic.