使用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>&nbsp;</td></tr><tr><td><div><a 
</div></td></tr><tr><td>&nbsp;</td></tr><tr><td><div><a href="xxxxxxxxxxxxxxx" target="_blank">Suppress (Snooze) </a></div><div>
</div></td></tr><tr><td>&nbsp;</td></tr><tr><td><div><a 
</div></td></tr><tr><td>&nbsp;</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. 

最新更新