Search code examples
powershellwmi

How to check/repair WMI remotly


How can we check WMI is working or not on multiple servers? Manually we can check by WMI service. If WMI is corrupt can we repair manually?


Solution

  • Get your Computer list first,

    $Computers = Get-Content C:\Computerlist.txt
    

    Then you can use this Function:

    Function Test-WMIStatus
    {
    Param(
    [Array]$Computers
    )
    
    $Report = @()
    
    Foreach ($Computer in $Computers)
    {
    
    $Row = "" | Select Computer,WMIStatus
    $Row.Computer = $Computer
    
            Try 
            {
            $WMI = Get-WmiObject -Class win32_ComputerSystem -ComputerName $Computer -ErrorAction Stop
            $Row.WMIStatus = $true
            }
    
            Catch 
            {
            $Row.WMIStatus = $false
            }
    
        $Report += $Row
    }
    
    Return $Report
    }
    

    To run it:

    Test-WMIStatus -Computers $computers
    

    Regarding WMI Repair:

    Most common WMI Problems are related to Firewall block, Winmgmt Service (Windows Management Instrumentation) is Stopped/Disabled etc. you can automate those tasks of course, but it needs more code...