Windows: Powershell script to fix and repair WMI


this script repairs and recreates the WMI Repository of a Windows. For example, this occurs sometimes if you clone a Windows machine with an installed SCCM/SMS Client. The typical error in this case is “Failed to open to WMI namespace ‘\\.\root\CCM\SoftwareUpdates\DeploymentAgent’ (8007045b)”

Lasts start. Start a Powershell console as Administrator. Stop all services. Sometimes other services depends on the WMI Service and does not accept a stop request. Therefore you cannot stop the WMI service. TrendMicro Office is such a service. You have to kill them by TaskManager.

# Stop WMI
# Only if SCCM/SMS Client is installed. Stop ccmexec.
Stop-Service -Force ccmexec -ErrorAction SilentlyContinue
Stop-Service -Force winmgmt

(Re)Register WMI binary components

foreach ($sWMIPath in @(($ENV:SystemRoot+"\System32\wbem"),($ENV:SystemRoot+"\SysWOW64\wbem"))){
	if(Test-Path -Path $sWMIPath){
		push-Location $sWMIPath
		foreach($sBin in $aWMIBinaries){
			if(Test-Path -Path $sBin){
				$oCurrentBin=Get-Item -Path  $sBin
				Write-Host " Register $sBin"
				& $oCurrentBin.FullName /RegServer
				# Warning only for System32
				if($sWMIPath -eq $ENV:SystemRoot+"\System32\wbem"){
					Write-Warning "File $sBin not found!"

Reregister WMI Managed Objects

if([System.Environment]::OSVersion.Version.Major -eq 5) 
   foreach ($sWMIPath in @(($ENV:SystemRoot+"\System32\wbem"),($ENV:SystemRoot+"\SysWOW64\wbem"))){
   		if(Test-Path -Path $sWMIPath){
			push-Location $sWMIPath
			Write-Host " Register WMI Managed Objects"
			$aWMIManagedObjects=Get-ChildItem * -Include @("*.mof","*.mfl")
			foreach($sWMIObject in $aWMIManagedObjects){
				$oWMIObject=Get-Item -Path  $sWMIObject
				& mofcomp $oWMIObject.FullName				
   if([System.Environment]::OSVersion.Version.Minor -eq 1)
   		& rundll32 wbemupgd,UpgradeRepository
   		& rundll32 wbemupgd,RepairWMISetup
	# Other Windows Vista, Server 2008 or greater
	Write-Host " Reset Repository"
	& ($ENV:SystemRoot+"\system32\wbem\winmgmt.exe") /resetrepository
	& ($ENV:SystemRoot+"\system32\wbem\winmgmt.exe") /salvagerepository

Starting services

Start-Service -Force winmgmt
Start-Service -Force ccmexec -ErrorAction SilentlyContinue


Update 04/04/2014: Modified the script. From now, no more WMI queries are done by the script. The OS version is determined by the System.Environent class.

Advertisment to support

Fix and repair Windows WMI
Version: 1.1

Fix and repair Windows WMI. New Version without any WMI Queries.

Author:Michael Albert
Category:Powershell Scripts
Date:April 4, 2013
5.4 KiB

6 thoughts on “Windows: Powershell script to fix and repair WMI”

  1. Thanks for this script, but I’m having trouble even running it on my windows 2008 host.

    AuthorizationManager check failed.
    At line:1 char:13
    + .\fixwmi.ps1 <<<<
    + CategoryInfo : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

    I had the execution policy set to remote-signed, but now get-execution policy throws an error.

    Get-ExecutionPolicy :
    At line:1 char:20
    + Get-ExecutionPolicy <<<<
    + CategoryInfo : NotSpecified: (:) [Get-ExecutionPolicy], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetExecutionPo

    I've heard this is because of WMI being broken, but I can't use your script.

    1. Hi John, try the new updated script V1.1. I’ve replaced all WMI queries to determine the OS version with .NET System.Environment function calls.

  2. Is there a solution for windows Server 2003 SBS? I get stalled at can’t stop the service.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.