powershell - 使用 PowerShell 识别以 RD* 开头的实例名称
问题描述
我正在尝试查找所有超出我的阈值限制的 Azure 实例。我的系统检测到了这些实例,现在我想从文本中提取所有机器并采取行动。我只有 PowerShell 作为选项来识别以下文本中以 RD* 开头的所有实例。
@{DescriptionEntryId=343578460;
Issue:
</td><td>
An xxxxxx has been triggered for 59 distinct instances of this xxxxxxx
</td></tr><tr><td>Description:</td><td>setting up this to identify issue</td></tr><tr><td>Severity:</td><td>Warning</td></tr><tr><td colspan="2"><dl><dt>RDxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.393 and 6.054.</dd><dt>RDxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.722 and 6.813.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.481 and 5.909.</dd><dt>RDxxxxxxxxxx</dt><dd>The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 1.412 and 6.588.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 3.375 and 6.24.</dd><dt>RDxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.382 and 6.863.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 0.418 and 11.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 3.059 and 6.667.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.255 and 7.5.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.545 and 5.291.</dd><dt>RDxxxxxxxxxx</dt><dd>The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 1.691 and 5.6.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 2 and 6.755.</dd><dt>RDxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes</div><div>
View additional information about why the xxxx fired
</div></td></tr><tr><td> </td></tr><tr><td><div><a
</div></td></tr><tr><td> </td></tr><tr><td><div><a href="xxxxxxxxxxxxxxx" target="_blank">Suppress (Snooze) </a></div><div>
</div></td></tr><tr><td> </td></tr><tr><td><div><a
</div></td></tr><tr><td> </td></tr></tbody></table></div></div></span>; RenderType=Html; Initials=; SubmittedByDisplayName=}
解决方案
您似乎正在显示某种 HTML 报告,并希望使用 Powershell 对其进行解析。对于此解决方案,您需要将报告保存在 .html 文件中。
假设您这样做并将报告保存到磁盘,D:\Report.html
然后您可以执行以下操作:
# read the report file as string
$htmlReport = Get-Content -Path 'D:\Report.html' -Raw
# create a Regular Expression object to capture the RD machines and their issues
$regex = [regex] '<dt>(?<Name>RD[^<]*)</dt><dd>(?<Issue>[^<]+)</dd>'
$matches = $regex.Match($htmlReport)
while ($matches.Success) {
New-Object -TypeName PSObject -Property ([ordered]@{ Name = $matches.Groups['Name'].Value; Issue = $matches.Groups['Issue'].Value })
$matches = $matches.NextMatch()
}
使用您提供的报告,这将产生
Name Issue
---- -----
RDxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.393 and 6.054.
RDxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.722 and 6.813.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.481 and 5.909.
RDxxxxxxxxxx The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 1.412 and 6.588.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 3.375 and 6.24.
RDxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.382 and 6.863.
RDxxxxxxxxxxxx The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 0.418 and 11.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 3.059 and 6.667.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.255 and 7.5.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.545 and 5.291.
RDxxxxxxxxxx The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 1.691 and 5.6.
RDxxxxxxxxxxxx The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 2 and 6.755.
推荐阅读
- css - 这个布局可以用 Flexbox 完成吗
- reactjs - React 不会在状态更改时重新渲染
- java - Apache POI:迭代 docx.getBodyElements() 时如何获取页码
- python - 将字符串的csv列转换为日期时间
- elasticsearch - 弹性搜索 , And 运算符 , 嵌套字段
- excel - 如果满足两个不同的特征,我需要一个 Excel 公式,它将数据从一张表移动到另一张表
- javascript - .innerHTML 内的图片链接
- javascript - 用 Jest 进行测试。应该抛出的测试失败
- r - seq_len 在 rcpp 中无法识别
- javascript - 当我尝试单击功能时,Chrome 扩展程序出错