Search This Blog

Sunday, October 20, 2019

HOW TO REPAIR THE WMI

USING POWERSHELL FOR REMOTE COMPUTERS

$Computername = 'Computer01.domain.com'

$Command = {
    
    (Get-Service tmlisten).WaitForStatus('Stopped','00:05:00')
    
    Stop-service winmgmt -Force
    (Get-Service winmgmt).WaitForStatus('Stopped','00:05:00')

    $sysroot = $env:SystemRoot
    Rename-Item 'c:\windows\system32\wbem\repository' 'c:\windows\system32\wbem\repository.old'
    #rd -recurse -force repository
    regsvr32 /s $sysroot\system32\scecli.dll
    regsvr32 /s $sysroot\system32\userenv.dll
    gci -filter  *.dll | % {regsvr32 /s $_.Name}
    gci | where {'.mof', 'mfl' -contains $_.Extension}| % {mofcomp $_.Name} 
    mofcomp -n:root\cimv2\applications\exchange wbemcons.mof
    mofcomp -n:root\cimv2\applications\exchange smtpcons.mof
    
}

$s = New-PSSession -ComputerName $Computername -Authentication Kerberos -UseSSL
Invoke-Command -Session $s -ScriptBlock $command

**********************************************************************

MANUAL WMI REPAIR
  1. Stop WMI Service
  2. Go to %windir%\System32\wbem
  3. Rename the folder called "Repository" to "Repository.bak"
  4. Open an Admin CMD
  5. CD to %windir%\System32\wbem
  6. Run the following command:
    for /f %s in ('dir /b /s *.dll') do regsvr32 /s %s
  7. CD to C:\ (root directory)
  8. Run the following command:
    for /f %s in ('dir /s /b *.mof *.mfl') do mofcomp %s
  9. Reboot the PC (optional)

No comments:

Post a Comment