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 {            
 param(            
  [string]$path            
 )            
             
 if ($path) {            
   if (-not(Test-Path $path)){            
    Throw "$path not found"            
   }            
   else {            
    $path            
    $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

 Comment 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: