pato pato - 2 months ago 7x
PowerShell Question

Powershell select-string using -inputobject for HV replication

I'm trying to write a query of the replication status of our VMs. I would like to be more selective in what I'm looking for, however.

I can run this:

PS C:\Users\hc> Get-VMReplication -computername servername
and it'll return this:

Image 1

I'd like it to return the line in the list when there is a match, or nothing when there isn't. Ive so far gotten it to select an item from the list by writing it as this:

PS C:\Users\hc> ((Get-VMReplication -computername servername | select-string -inputobject {$_.Health} -pattern “Normal”) -like “Normal”)

but it unfortunately only displays a list of Normal:

Image 2

Ultimately I would like it it to list the column headings and the entire row if possible but I'm unsure as to where to go next. (note that I've used the "Normal" pattern just so it would create entries in this list. The final product will look for "Warning" and "Critical")


Don't use Select-String, use Where instead.

Get-VMReplication -computername servername | Where{ $_.Health -eq "Normal"}

Or later down the road it would look like:

Get-VMReplication -computername servername | Where{ $_.Health -eq "Warning" -or $_.Health -eq "Critical"}