This PowerShell module provides some functionality to facilitate automating backup actions of a FortiGate device over SSH. This module also provides some basic functionality for troubleshooting FortiGate devices.
Here are some similar projects I am working on:
- Posh-Cisco (PowerShell Cisco Module)
- Posh-Juniper (PowerShell Juniper Module)
- Posh-Ubnt (PowerShell Ubnt Module)
This module depends on the following PowerShell modules:
PS> Save-Module -Name Posh-FortiGate -Path <path>
PS> Install-Module -Name Posh-FortiGate
- Backup-FortiGateConfig: Gets the configuration and writes it to a file.
- Get-FortiGateConfig: Gets the configuration.
- Get-FortiGateSystemStatus: Gets the system status.
- Get-FortiGateSystemPerformanceStatus: Gets the system performance status.
- Get-FortiGateSystemHAStatus: Gets the system HA (High-Availability) status.
- Get-FortiGateSystemSessionList: Gets the system session list.
This PowerShell command gets the configuration and writes it to a file.
PS> Backup-FortiGateConfig -HostAddress "192.168.1.99" -HostPort 22 -Credential (Get-Credential) -FilePath "$([Environment]::GetFolderPath(“MyDocuments”))\config.txt"
Advanced Options:
- Specify the
-AcceptKey
flag to automatically accept SSH key. - Specify the
-Full
flag to retrieve full configuration with default values.
This PowerShell command gets the configuration.
PS> Get-FortiGateConfig -HostAddress "192.168.1.99" -HostPort 22 -Credential (Get-Credential)
Advanced Options:
- Specify the
-AcceptKey
flag to automatically accept SSH key. - Specify the
-Full
flag to retrieve full configuration with default values.
This PowerShell command gets the system status.
PS> Get-FortiGateSystemStatus -HostAddress "192.168.1.99" -HostPort 22 -Credential (Get-Credential)
Advanced Options:
- Specify the
-AcceptKey
flag to automatically accept SSH key.
This PowerShell command gets the system performance status.
PS> Get-FortiGateSystemPerformanceStatus -HostAddress "192.168.1.99" -HostPort 22 -Credential (Get-Credential)
Advanced Options:
- Specify the
-AcceptKey
flag to automatically accept SSH key.
This PowerShell command gets the system HA (High-Availability) status.
PS> Get-FortiGateSystemHAStatus -HostAddress "192.168.1.99" -HostPort 22 -Credential (Get-Credential)
Advanced Options:
- Specify the
-AcceptKey
flag to automatically accept SSH key.
This PowerShell command gets the system session list.
PS> Get-FortiGateSystemSessionList -HostAddress "192.168.1.99" -HostPort 22 -Credential (Get-Credential)
Advanced Options:
- Specify the
-AcceptKey
flag to automatically accept SSH key.
Before you create scripts that use this module, you should create a readonly_admin
profile and readonly_User
user to be used for the PSCredentials.
config system accprofile
edit "readonly_admin"
set mntgrp read
set admingrp read
set updategrp read
set authgrp read
set sysgrp read
set netgrp read
set loggrp read
set routegrp read
set fwgrp read
set vpngrp read
set utmgrp read
set wanoptgrp read
set endpoint-control-grp read
set wifi read
next
end
config system admin
edit "readonly_user"
set trusthost1 192.168.1.1 255.255.255.255
set accprofile "readonly_admin"
set comments "User for PowerShell backup and troubleshooting tasks"
set vdom "root"
set password enterastrongpasswordhere
next
end
These PowerShell functions were tested on the following FortiGate devices:
- FortiGate 100D (SW version: 5.4.1)
- FortiGate 1000D (SW version: 5.4.1)
- Added security considerations section to documentation
- Fixed issue with prompt being $ instead of #
- Fixed issue with backup file being UTF-16 instead of ASCII
- Added documentation
- Added support to backup configuration to a file (Backup-FortiGateConfig)
- Added support to backup full configuration (with default values) to a file (Backup-FortiGateConfig -Full)
- Added support to get configuration (Get-FortiGateConfig)
- Added support to get full configuration (with default values) (Get-FortiGateConfig -Full)
- Added support to get system status (Get-FortiGateSystemStatus)
- Added support to get system performance status (Get-FortiGateSystemPerformanceStatus)
- Added support to get system (HA) high-availability status (Get-FortiGateSystemHAStatus)
- Added support to get system session list (Get-FortiGateSystemSessionList)
- Test on more devices
- ...