Is there any Script for Rebuilding WMI

checkingrandom 206 Reputation points
2024-07-03T07:30:01.7033333+00:00

Hello Microsoft Community,

I hope this message finds you well.

I am currently facing issues with the Windows Management Instrumentation (WMI) on my systems and need to rebuild it to restore its functionality.

Could anyone kindly provide or point me towards a reliable script for rebuilding WMI in Windows? Detailed instructions or best practices related to this process would also be greatly appreciated.

Thank you in advance for your assistance!

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,188 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,095 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,633 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,981 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Nikit Patiyawala 0 Reputation points
    2024-07-03T08:31:22.34+00:00

    Hi

    Please try the below steps.

    Verify the WMI Repository

    1. Run the following command to check the consistency of the WMI repository:
         winmgmt /verifyrepository
      
    2. If the repository is consistent, you will see a message indicating so. If not, proceed to the next step. Salvage the WMI Repository Run the following command to attempt to salvage the repository:
         winmgmt /salvagerepository
      
    3. Verify the repository again using the winmgmt /verifyrepository command. If it is still inconsistent, proceed to the next step.
       **Reset the WMI Repository**
      
    4. Run the following command to reset the repository:
         winmgmt /resetrepository
      
    0 comments No comments

  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 34,271 Reputation points Microsoft Vendor
    2024-07-04T01:27:05.4533333+00:00

    Hi,

    You can run the following commands in an elevated command prompt. It recompiles all the built-in WMI provider MOF files and re-register the WMI provider DLLs.

    1. Stop the WMI service and set it to disabled:
         sc config winmgmt start= disabled
         net stop winmgmt /y
      
    2. Navigate to the WBEM folder:
         %systemdrive%
      
    3. Re-register the WMI providers:
         for /f %s in ('dir /b *.dll') do regsvr32 /s %s
      
    4. Set the WMI service back to Auto and start the service:
         sc config winmgmt start= Auto
         net start winmgmt 
      
    5. Recompile the MOF files:
         dir /b *.mof *.mfl | findstr /v /i uninstall > moflist.txt & for /F %s in (moflist.txt) do mofcomp %s 
      

    Please note that this sets the WMI repository back to its initial state when the operating system was installed. WMI will lose all the information that was gathered over time about the system itself, applications, services, and other entities around it.

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.