Using PowerShell to install the WDDM video driver

PowerShell logoYesterday 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: http://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.

About these ads

About Robert van den Nieuwendijk
Robert van den Nieuwendijk is a freelance senior systems engineer with over 25 years of experience in the IT industry. His main focus is VMware vSphere and Microsoft Windows Server. He tries to automate as much of his work as possible using Microsoft Windows PowerShell. Robert is the author of the book “Learning PowerCLI”. Robert is a frequent contributor and moderator at the VMware VMTN Communities. He has a bachelor degree in software engineering and holds the following IT certifications and accreditations: VSP 5, VTSP 5, VCP4-DCV, VCP5-DCV, VCA-Cloud, VCA-WM, MCSE, MCSA, MCP, MCP+I, and ITIL Foundation. In 2012, 2013 and in 2014 Robert received the VMware vExpert title for his contribution to the community of VMware users over the past year.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 660 other followers

%d bloggers like this: