In short, I need to find a specific line in a long file that starts with "set ip " and continues with some parameter that I need to replace. this line appears multiple times in the file so I need to find it between 2 specific lines.
The longer story: We will soon get to configure many FortiGate Firewalls for our offices, most of the settings, policies etc. will be the same but the external IP changes, some other addresses change etc. So I'm trying to make a powershell script that will take an existing config (which might change) and find the specific lines I need and replace them. I tried with regex but couldn't make it work for me on multiple lines. basically for a reference I need to find the "set ip " in the following part:
config system interface
edit "wan1"
set vdom "root"
set ip 7.7.7.7 255.255.255.252
set allowaccess ping https ssh
set ident-accept enable
set type physical
set scan-botnet-connections block
set alias "WAN1"
set role wan
set snmp-index 1
next
(IP was changed for security) and so on. what I've got so far is:
get-content .\Fortigate.conf | select-string -pattern "^#","set uuid " -notmatch
sadly nothing I tried to cut that part of text to search only there worked. for example with regex I tried:
get-content .\Fortigate.conf | select-string -pattern "^#","set uuid " -notmatch | select-string -Pattern '(?m)edit "wan1".*?end'