Using Powershell for bulk SSH commands on Fortigate firewalls, etc.
I’ve been working with a customer with a large stack of Fortigate firewalls. Quite frequently there is a requirement to run commands against some or all of the firewalls. While config management can be performed via the FortiManager, after trialling it we realized there were simply too many limitations for their requirements. Thankfully bulk commands can be performed with this handy PowerShell SSH Module:
http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library. As an example, I’ve built a quick power shell script as an example of how this can be used.
1.) Populate a list of your firewall IP addresses in a CSV firewall called Firewalls.csv.
2.) Example: Enable SCP on Fortigate firewalls (to be used in a running config backups, etc.)
Import-Module .\SSH-Sessions.psd1
$Firewalls = get-content .\firewalls.csv
$Username = “firewallusername”
$Password = “firewallpassword”
foreach ($Firewall in $Firewalls){
New-SshSession $Firewall -Username $Username -Password $Password
Invoke-SshCommand $Firewall -command ‘config system global
set admin-scp enable
end’
}
Note: In a production environment you would want to a) Use Cert based authentication or b) Encrypt your User/Name password (or perhaps prompt for a credential when script is ran). It goes without saying – backup your firewall config before you make any changes! 🙂
In my next post I’ll cover using pscp.exe to backup your firewall config in a PowerShell script.
2 Responses to “Using Powershell for bulk SSH commands on Fortigate firewalls, etc.”
Trackbacks / Pingbacks
- March 17, 2015 -
What if the devices have 2FA configured. Does this mean this will only work if the username/password is local and not using 2FA?
Thanks!