Using PowerShell to install the WDDM video driver
December 7, 2011 Leave a comment
Yesterday we discovered that the system hangs, we sometimes have on our Windows Server 2008 R2 systems are caused by the video device driver. Because we don’t want to install another video driver manually in all our Windows 2008 R2 systems, we needed a script to do this.
The problem
Since the migration from VMware Infrastructure 3.5 to VMware vSphere 4.1 we noticed that our Windows 2008 R2 system sometimes hang. We could even force a hang by removing a hidden network device. This was very annoying because we moved to the VMXNET3 network driver and needed to remove the old hidden device. The IP settings were in this hidden device and if we didn’t remove them, we could not put the IP settings on the VMXNET3 device. With every Windows Server 2008 R2 migration we had this problem. And we thought that a bug in the Windows hidden device removal was the cause of this problem.
Yesterday we found two VMware Knowledge Base articles that describe our problem:
Troubleshooting SVGA drivers installed with VMware Tools on Windows 7 and Windows 2008 R2 running on ESX 4.x
and
WDDM and XPDM graphics driver support with ESX 4.x, Workstation 7.0, and Fusion 3.0.
The second article shows that only the WDDM video driver is supported by VMware on Microsoft Windows Server 2008 R2. And not the SVGA II driver that we used.
The solution
First we needed to find out how big the problem is. The PowerCLI command in Listing 1 gave us the number of Microsoft Windows Server 2008 R2 systems in our vSphere environment. In our case the number was 103. That are to many systems to path manually.
Get-View -ViewType VirtualMachine -Property Config.GuestFullname ` -Filter @{"Config.GuestFullname"="Microsoft Windows Server 2008 R2 \(64-bit\)"} | ` Measure-Object
Listing 1. PowerCLI script to count the number of Microsoft Windows Server 2008 R2 systems.
The backslashes in the filter part of the command from listing 1 are used to escape the parenthesis. Remember that the value in the Get-View filter is a regular expression and not a string value. Parenthesis are special characters in a regular expression.
Then we wanted a list of the video drivers installed.
Get-View -ViewType VirtualMachine -Property Name,Config.GuestFullname ` -Filter @{"Config.GuestFullname"="Microsoft Windows Server 2008 R2 \(64-bit\)"} | ` Select-Object -Property Name,@{N="Display Device";E={(Get-WMIObject -Query "Select * from Win32_PnPSignedDriver Where DeviceClass='DISPLAY'" ` -ComputerName $_.Name).DeviceName}}
Listing 2. PowerCLI script to list the video device drivers installed in the Microsoft Windows Server 2008 R2 systems.
The listing showed us that only a few systems had the WDDM driver installed. So we needed a script to install the WDDM video driver. I had never installed a driver from a script and Google was my first bet to find a way to do this. So I typed in Google: “windows script install wddm driver”.
Luckily one of the first hits was a VMware VMTN Communities thread Add vmware wddm video driver per script in which meistermn showed how to use the pnputil utility to install the WDDM driver.
I wanted to make his script a bit more robust. By checking if the script runs on a Microsoft Windows Server 2008 R2 system, if the WDDM driver is not yet installed and check if the VMware Tools are installed. That resulted in the following PowerShell script to install the WDDM video driver:
<# .SYNOPSIS This script installs the "VMware SVGA 3D (Microsoft Corporation - WDDM)" video driver on a Microsoft Windows Server 2008 R2 system. .DESCRIPTION This script installs the "VMware SVGA 3D (Microsoft Corporation - WDDM)" video driver on a Microsoft Windows Server 2008 R2 system. It uses WMI and the pnputil.exe utility. If the driver is installed the system will be rebooted. .INPUTS None .OUTPUTS None .NOTES Author: Robert van den Nieuwendijk Blog: https://rvdnieuwendijk.com/ Date: December 7th, 2011 #> # Check to make sure this script only runs on Microsoft Windows Server 2008 R2 system. $OperatingSystem = Get-WmiObject -Class Win32_OperatingSystem if ($OperatingSystem -and $OperatingSystem.Name -like "Microsoft Windows Server 2008 R2 *") { # Get the display device driver. $DisplayDriver = Get-WMIObject -Query "Select * from Win32_PnPSignedDriver Where DeviceClass='DISPLAY'" # Check to see if we have the WDDM display device driver. if ($DisplayDriver -and $DisplayDriver.DeviceName -ne "VMware SVGA 3D (Microsoft Corporation - WDDM)") { # We have the wrong driver. We need to install the correct one. # Check if the VMware Tools are installed and the WDDM driver can be found. $WddmFile = "c:\program files\common files\vmware\drivers\wddm_video\vm3d.inf" if (Test-Path -Path $WddmFile) { # Install the WDDM driver and restart the computer. pnputil -i -a "$WddmFile" Restart-Computer } else { Write-Warning "WDDM driver file $WddmFile not found on this computer." } } else { Write-Output "The WDDM display driver is already installed on this computer." } } else { Write-Output "This script is only intended for the Microsoft Windows Server 2008 R2 operating system." }
Listing 3. Script to install the WDDM video driver on Microsoft Windows 2008 R2 systems.
We use this script from an Altiris server. Because we want Windows administrators that are not vSphere administrators to be able to install the WDDM driver. But you can also use the PowerCLI Invoke-VMScript cmdlet to run this script from PowerCLI.