SCOM agent install Failed to uninstall SDK MOF

Have a customer with a lot of machines that have a broken WMI, so I guess I’d blog about possibilities to solve the issue for the agent installation part.
I refer to a blog posting by the Manageability Team Blog.
So, you could make a script that does something like this:
Xcopy \\aworkingmachine\c$\windows\system32\Wbem c:\windows\system32\wbem /i /y
cd \windows\system32\wbem
For /f %s in (‘dir /b *.mof *.mfl’) do mofcomp %s
net stop ccmexec
net stop winmgmt
net start winmgmt
net start ccmexec
and your agent installation should now work. Or something else is wrong ;D
You can actually test if this is the problem by:
Start wbemtest. Connect to root\wmi. enum classes and type Eventtrace. If you get an error immediately run the above commands and try again.
Additional Comment:
A reader Tolga Balci, noted to me that the command in the script should contain only one percentage sign (%s) instead of two (%%s). I remember taking the double percentage straight from one of the batch files we have running. But as it didn’t work for Tolga until they changed it to the single % I adjusted that as well on this page. If in your case that doesn’t run you can always try to make it %%s. B) Thanks Tolga!