PowerShell for Windows Admins

Dec 5 2011   1:41PM GMT

Testing the WMI repository

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


Occasionally the WMI database becomes corrupt. Strangely I have seen this happening more often recently because of the creation of virtual machines from templates – if the template is corrupt so will be the virtual machines.

With Windows Vista and above we can use the winmgmt utility to test the repository. I’ve gotten used to the verb-noun syntax of PowerShell so decided to create a wrapper rather than try and remember the syntax

function test-wmirepository {            
 if ($path) {            
   if (-not(Test-Path $path)){            
    Throw "$path not found"            
   else {            
    $exp = "winmgmt /verifyrepository $path"            
 else {            
  $exp = "winmgmt /verifyrepository"            
 Invoke-Expression -Command $exp            

The utility can test the repository (default) or if the path to a backup file is given then that can be tested instead.

PS> test-wmirepository

WMI repository is consistent

if you don’t get the message about the repository being consistent then you have a problem. We’ll see how to fix that later.

How do you take a backup of the repository? – We’ll get to that later as well

2  Comments on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • kickinChrispy
    how do I run this on a remote machine?
    0 pointsBadges:
  • Richard Siddaway
    A few possibilities for instance - Create and enter a PowerShell remoting session connected to your remote server. Wrap the function in a script block and use invoke-command. RDP to the box and run the exe at a PowerShell prompt
    9,575 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: