Powershell select-string 使用 -inputobject 进行 HV 复制

Powershell select-string using -inputobject for HV replication

我正在尝试编写对我们 VM 的复制状态的查询。不过,我想 select 更加关注我正在寻找的东西。

我可以运行这个:

PS C:\Users\hc> Get-VMReplication -computername 服务器名 它会 return 这个:

Image 1

我希望它 return 匹配时列表中的行,或者不匹配时不匹配。到目前为止,我把它写成 select 列表中的一个项目:

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

但不幸的是它只显示了一个正常的列表:

Image 2

最终我希望它尽可能列出列标题和整行,但我不确定下一步该去哪里。 (请注意,我使用 "Normal" 模式只是为了在此列表中创建条目。最终产品将查找 "Warning" 和 "Critical")

不要使用 Select-String,请使用 Where

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

或者稍后它看起来像:

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