-3

Need help in sorting out a data from my output, I want to show only a output saying ALL OK when STATE is RUNNING, and NOT OK if the STATE is Faulted (or any other string).

How can I achieve this?

Invoke-Command -ComputerName XXXXX,XXXX -ScriptBlock { hastatus -sum; VXPRINT -VPl } -credential XXXXX

Output:

-- SYSTEM STATE
-- System               State                Frozen              

A  XXXXXXXXXXXXX        RUNNING              0                    
A  XXXXXXXXXXXXX        RUNNING              0   
2
  • that does not look like all the info returned by a call to Invoke-Command that refers to a remote system. there is usually a runspace ID and a PSComputerName in the properties returned. are you sure that is ALL the data returned by the call? Commented Nov 20, 2018 at 15:22
  • hastatus -summary isn't a native powershell command so you'll need to deal the (table-like) string output it returns: stackoverflow.com/questions/38036175/… Commented Nov 20, 2018 at 15:41

1 Answer 1

1

Just following your output, I think something like this is what you want?

$output = @"
-- SYSTEM STATE
-- System               State                Frozen              

A  XXXXXXXXXXXXX        RUNNING              0                    
A  XXXXXXXXXXXXX        RUNNING              0  
A  XXXXXXXXXXXXX        ANYTHINGBUTRUNNING   0 
"@

($output -split '\r?\n') | ForEach-Object {
    if ($_ -match '^[A-Z]\s+\w+') {
        $system = $matches[0]
        if ($_ -match '\bRUNNING\b') {
            "$system  ALL OK"
        }
        else {
            "$system  NOT OK"
        }
    }
}

The resulting PowerShell console output will be:

A  XXXXXXXXXXXXX  ALL OK
A  XXXXXXXXXXXXX  ALL OK
A  XXXXXXXXXXXXX  NOT OK
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.