Link to home
Start Free TrialLog in
Avatar of Amin El-Zein
Amin El-Zein

asked on

ip list command generator power shell script

Hello,
I have txt file that contation list of ip for example
1,1,1,1
0.0.0.0/24
172.16.0.0/24
172.16.0.1
I want to make a script with power shell
that generate anew file for my MikroTik to add the ips to address list the final file will be for example: list.rsc
/ip firewall address-list
add address=1,1,1,1 comment="lsit" list=anti
add address=0.0.0.0/24  comment="lsit" list=anti
add address=172.16.0.0/24  comment="lsit" list=anti
add address=172.16.0.1 comment="lsit" list=anti

thanks.
Avatar of oBdA
oBdA

Something like this?
$inFile = '.\iplist.txt'
$outFile = '.\list.rsc'
$comment = 'lsit'
$list = 'anti'
$(
	'/ip firewall address-list'
	Get-Content -Path $inFile | ForEach-Object {
		"add address=$($_) comment=`"$($comment)`" list=$($list)"
	}
) | Set-Content -Path $outFile

Open in new window

Avatar of Amin El-Zein

ASKER

thank u
i have a special case that some ip in the mail list is like
1.1.1.1 #comment
i just want to take the ip or the ip with subnet
also i have a blank raw somtimes
thanks.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial