-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   
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 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? – Lee_Dailey Nov 20 '18 at 15:22
  • [`hastatus -summary`](https://sort.veritas.com/public/documents/vcs/5.1/aix/manualpages/html/manpages/man1m/hastatus.1m.html) isn't a native powershell command so you'll need to deal the (table-like) string output it returns: https://stackoverflow.com/questions/38036175/how-to-convert-string-to-table-or-objects-in-powershell – henrycarteruk Nov 20 '18 at 15:41

1 Answers1

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
Theo
  • 57,719
  • 8
  • 24
  • 41