working with external commands an messages RRS feed

  • Question

  • Good day community,

    first i'm soory for my poor english but i try to keep my question simple :)

    I'm writing a "little" script for troubleshooting WMI on different systems.
    Now i want to start the command "winmgmt /verifiy repository" which response with "WMI repository is consistence" or with "WMI repository is not consistent"
    I want to work with the response from the command line to start different things.
    I try to explain that.

    If the response is "WMI repository is consistence" write-host "everthing OK" and then break.
    Else ...
    Here's a little Code that i tried:

    If ($(test-wmirepository).Status -eq "WMI repository is consistent")
    			$Status_ok = 1
    			Write-Host "All WMI works fine"

    The test-wmirepository is a function that is declared in the head of the script.

    I hope that someone can help me or give me some hints to solve that problem.

    Thanks in advance

    • Changed type KaiWenzel Tuesday, January 10, 2012 7:25 AM
    Monday, January 9, 2012 2:37 PM


  • So i found a solution for my issue.

    $LASTEXITCODE worked for my "problems :-)

    • Marked as answer by KaiWenzel Tuesday, January 10, 2012 7:26 AM
    Tuesday, January 10, 2012 7:25 AM