Technical World: November 2018

Tuesday, November 20, 2018

Address object creation script for fortigate using powershell

1. Create a  csv file named Server.csv with below format with all the address objects to be created
do not change the column names as they are refereed in the script
Assetname IPAddress    


ad-(ip address)(Ip address)


2. Create a notepad file and copy the below test and save it as script.ps1
$inputCSV = "c:\Servers.csv"
$outputFile = "c:\Addresses.txt"
Add-Content -PassThru $outputFile -Value "config firewall address"
Import-Csv $inputCSV | ForEach-Object {
 $Name = $_.Assetname
 $IP = $_.IPAddress
 Add-Content -Path $outputFile -Value "edit $Name"
 Add-Content -Path $outputFile -Value "set subnet $IP 255.255.255.255"
 Add-Content -Path $outputFile -Value "next"
}
Add-Content -PassThru $outputFile -Value "end"


3. Save the Servers.csv and script.ps1 files in C: on machine
4. open power shell and goto c drive and run .\script.ps1