WMI Check repair or fix script

Posted on 2011-10-11
Last Modified: 2012-05-12
I am in desperate need of a script that will check if WMI is working correctly on winXP and Win7 (can be separate scripts) and only repair or fix if needed. I don't want it to run a repair or fix if WMI is working, only if it is broken. I have about 3400 machines out of about 17000 that I think WMI is broken. I plan to run this in a startup script in group policy. I'm not even sure if this is possible, but if it is I will be very grateful for any help.
Question by:fishewa
    LVL 23

    Expert Comment

    by:Nagendra Pratap Singh
    run this in an elevated command prompt

    wmic os

    if this works then your WMI is at least partially working. You can redirect the output to a text file and make reports.

    Nest steps are

    net stop winmgmt

    cd  C:\Windows\System32\Wbem\

    ren Repository   reposiold

    net start winmgmt


    How can you have 17000 broken out of 3400?
    LVL 16

    Expert Comment

    For a more comprehensive WMI rapair than just rebuilding the repository, you can script the following to run (batch files, PowerShell, VBScript, etc).
    net stop winmgmt /y
    cd /d %windir%\system32\wbem
    if exist %windir%\system32\wbem\repository.bak rmdir /s /q repository.bak
    rename %windir%\system32\wbem\repository repository.bak
    for %i in (*.dll) do regsvr32 /s %i
    for %i in (*.exe) do %i /RegServer
    net start winmgmt

    Open in new window

    After running this you will need to wait a few minutes for the repository to repair itself and then reboot the machine.
    LVL 16

    Expert Comment

    And maybe do a recompile of the mof files as well with mofcomp. So:
    for %i in (*.mof) do mofcomp %i

    Open in new window


    Author Comment

    Thank you for your posts. I have the repair solution as you have posted, but I was hoping that I could find something that would check if WMI was broken and fix it only if it is broken. I don't want to run a fix on every machine if it doesn't need it.
    LVL 16

    Accepted Solution

    Microsoft have a pretty comprehensive WMI diagnostic script (WMIDiag). Download it here. Information on the tool here. If you want something less comprehensive you can just have a small script which could check some key classes to see if they're working. So on every machine query root\cimv2\Win32_OperatingSystem, root\cimv2\Win32_ComputerSystem and maybe some of the SMS/SCCM client classes under root\CCM to see if they're working.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
    Viewers will learn the different options available in the Backstage view in Excel 2013.
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now