Check that WMI and the root\ccm namespace are healthy
Test the WMI service, the WMI repository, a basic WMI query and the root\ccm namespace of the SCCM client in one run.
LanguagePowerShell
What it does to the systemReads only. It changes nothing.
The SCCM client needs WMI. When WMI is damaged, the client stops reporting and installs fail with errors that point nowhere.
This script runs five short checks: the WMI service, the repository, a normal WMI query, the root\ccm namespace and a query to the client.
PowerShell
<#
Check WMI and the SCCM client namespace on this computer.
Run it on the computer, as an administrator. It only reads.
Example: .\Test-WmiHealth.ps1
#>
param(
[string]$Namespace = 'ccm'
)
$result = [ordered]@{
ComputerName = $env:COMPUTERNAME
WmiService = (Get-Service -Name Winmgmt).Status.ToString()
Repository = ''
BasicQuery = 'Failed'
CcmNamespace = 'Missing'
CcmClientQuery = 'Failed'
}
# Windows checks its own repository. The answer is one line of text.
$result.Repository = (& "$env:windir\System32\wbem\winmgmt.exe" /verifyrepository | Out-String).Trim()
# A query that works on every healthy Windows computer.
try {
$os = Get-CimInstance -ClassName Win32_OperatingSystem -ErrorAction Stop
if ($os.Caption) { $result.BasicQuery = 'OK' }
}
catch { $result.BasicQuery = $_.Exception.Message }
# Does the SCCM client namespace exist under root?
try {
$ns = Get-CimInstance -Namespace root -ClassName __NAMESPACE -Filter "Name = '$Namespace'" -ErrorAction Stop
if ($ns) { $result.CcmNamespace = 'Present' }
}
catch { $result.CcmNamespace = $_.Exception.Message }
# Can the SCCM client answer a query?
try {
$client = Get-CimInstance -Namespace "root\$Namespace" -ClassName SMS_Client -ErrorAction Stop
if ($client.ClientVersion) { $result.CcmClientQuery = "OK, client $($client.ClientVersion)" }
}
catch { $result.CcmClientQuery = $_.Exception.Message }
[pscustomobject]$result | Format-List
How to use it
- Save the script as
Test-WmiHealth.ps1on the computer. - Open PowerShell as an administrator. The repository check needs it.
- Run
.\Test-WmiHealth.ps1. - Read each line. A healthy client shows Running, a consistent repository, OK, Present and OK with a version.
Good to know
- The repository line is in the language of Windows. In English, a good result says the repository is consistent.
- A missing
root\ccmnamespace with healthy WMI means the client is not installed or the install broke. Install the client again. - If the repository is not consistent, try
winmgmt /salvagerepositorybefore you think about a reset.
WMI
repository
root\ccm
winmgmt
client health