0

it's a little bit hard to explain, but I want to write PowerShell script to search each interfaces that is configured in the set protocol ospf area statement to identify if any interface is not configured with authentication md5. if any interface is found while looping thru each interface, then I want to break out the loop and write-host "not compliant".

Below is my script. I skipped the first part of the script that scans each line in the config and do a select-string to find all the matches in the set protocols ospf area 0.0.0.0 interface vlan xxxx and stored in the $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
CBLT
  • 124
  • 1
  • 2
  • 10
  • 2
    Without knowing the content of your "c:\config.txt" nor your `$ospf_interface` it's impossible to help, your static line `$md5 = Select-String ...` doesn't make sense to me without referring to the currently iterated `$interface` it will always yield the same result –  Apr 07 '19 at 18:15
  • so lets say I have two config file1 and file2 – CBLT Apr 08 '19 at 03:45
  • I have config1.txt and config2.txt. config1 is configured with set protocols ospf area 0.0.0.0 interface vlan.3 authentication md5 set protocols ospf area 0.0.0.0 interface vlan.4 and config2 is configured with set protocols ospf area 0.0.0.0 interface vlan.7 authentication md5 0 set protocols ospf area 0.0.0.0 interface vlan.8 authentication md5 0 The result should be non-compliant for config1 since one interface is not configured with md5. Config2 should be compliant since two interfaces are configured with authentication. – CBLT Apr 08 '19 at 03:56
  • ospf_interface = select-string -path $file -pattern "^(set\sprotocols\sospf\sarea\s\d{1}\.\d{1}\.\d{1}\.\d{1}\sinterface\svlan\.\d{1,5})" – CBLT Apr 08 '19 at 03:57
  • Please [edit] your question to contain addititional/updated information. –  Apr 08 '19 at 07:26

0 Answers0