WMI Check repair or fix script

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.
fishewaAsked:
Who is Participating?
 
LearnctxConnect With a Mentor EngineerCommented:
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.
0
 
Nagendra Pratap SinghCommented:
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?
0
 
LearnctxEngineerCommented:
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.
0
 
LearnctxEngineerCommented:
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

0
 
fishewaAuthor Commented:
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.
0
All Courses

From novice to tech pro — start learning today.