Recently at work, I was met with something I had not seen before. The CPU, RAM, and other various hardware information was not showing. It was also reporting incorrectly to our WSUS server. On top of that, tools that needed that information were not working. I did some looking around to try to find what it was, originally people at work said it was a BIOS issue. The problem there is nothing on the BIOS changed and it was working fine before. Not to mention the BIOS reported everything correctly. So I did some digging and tried to view the information with Powershell.
Get-WMIObject Win32_Processor
This would give me a message that the Win32_Processor class was missing. This is rather odd, so I did some digging. Of all the results I got, the "last resort" did the trick. I also fixed part of the batch file they had to run it because one of the commands was just giving an error and there was so much text you never would notice otherwise.
rebuildWMI.bat
@ECHO OFF
sc config winmgmt start= disabled
net stop winmgmt /y
%systemdrive%
cd %windir%\system32\wbem
for /f %%s in ('dir /b *.dll') do regsvr32 /s %%s
wmiprvse /regserver
winmgmt /resetrepository
sc config winmgmt start= auto
net start winmgmt
for /f %%s in ('dir /s /b *.mof *.mfl') do mofcomp %%s
Then I decided to make a Powershell version as a challenge to myself. Unfortunately the executables I have to run mess with the flow with their / flags, but despite that it looks okay.
Rebuild-WMI.ps1
Set-Service -Name Winmgmt -StartupType Disabled
Stop-Service -Name Winmgmt
Set-Location $env:windir\system32\wbem
Get-ChildItem -Filter "*.dll" | ForEach-Object {
regsvr32.exe /s $_
}
wmiprvse.exe /regserver
winmgmt.exe /resetrepository
Set-Service -Name Winmgmt -StartupType Automatic
Start-Service -Name Winmgmt
Get-ChildItem .\* -Include ("*.mof", "*.mfl") | ForEach-Object {
mofcomp.exe $_
}
This should hopefully get you all set and going should the same problem happen to you.
No comments:
Post a Comment