powershell - 循环通过配置文件中的接口。如果发现接口没有配置认证,则显示结果
问题描述
这有点难以解释,但我想编写 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
解决方案
推荐阅读
- ruby-on-rails - 销毁操作的 RSpec 错误 - 没有路由匹配
- c - 当另一个线程正在读取标准输入时如何在 C 中获取光标位置
- swift - Swift 4 中的嵌套枚举
- python-3.x - 将 pandas 数据框写入 csv 但列之间没有空格 - sep'\t' 参数在 Python 3 中被忽略
- c - 如何使字符串数组的值不改变?
- hugo - 有什么方法可以为单个存储库和多个站点提供一个通用的 netlify.toml 文件?
- python - 根据文本文件中字符串“xyz”的外观删除传递给文本文件的最后一个字符输入
- sorting - 定义一个以三个数字为参数并返回两个较大数字的平方和的过程
- javascript - 如何解决输入连续性匹配
- javafx - 使用 JavaFX 创建六边形字段