首页 > 解决方案 > 循环通过配置文件中的接口。如果发现接口没有配置认证,则显示结果

问题描述

这有点难以解释,但我想编写 PowerShell 脚本来搜索在 set protocol ospf area 语句中配置的每个接口,以识别是否有任何接口未配置身份验证 md5。如果在通过每个接口循环时找到任何接口,那么我想打破循环并写入主机“不兼容”。

下面是我的脚本。我跳过了脚本的第一部分,它扫描配置中的每一行并执行一个选择字符串来查找 set protocols ospf area 0.0.0.0 interface vlan xxxx 中的所有匹配项并存储在 $ospf_interface

foreach($interface in $ospf_interface)
{
  $md5 = Select-string -path c:\config.txt -pattern "set\sprotocols\sospf\sarea\s0.0.0.0\sinterface\svlan\s\d{1,2}\sauthentication\smd5.*"
if($md5)  ##if md5 is found in the string, then write-host 
  { 
      Write-host "found"
      {break}
  }
### it does not seem to work correctly

标签: powershellospf

解决方案


推荐阅读