PowerFGT PowerShell Module

repository·master·Indexed 41 days ago

https://github.com/fortipower/powerfgt

A PowerShell module for automating the configuration and management of Fortinet FortiGate Firewalls. It provides cmdlets to manage network resources (addresses, VIPs, zones, static routes), security policies, routing (BGP, OSPF), system settings, and user configurations. Supports PowerShell 5, 6.x, and 7.x (Core), and includes experimental support for Virtual Domains (VDOMs) via the -vdom parameter.

Tokens
152.2K
Snippets
540
Records
645
Agent score
97%

What's inside PowerFGT

  1. Manage FortiGate resources with PowerFGT

    master

    PowerFGT uses standard PowerShell verbs to manage various FortiGate firewall resources. Most resource types support the following operations:

    • Get: Retrieve existing configurations.
    • Add: Create new configuration objects.
    • Copy: Duplicate existing configurations.
    • Set: Update or modify existing configurations.
    • Remove: Delete configuration objects.

    Example: Managing Address objects To manage firewall addresses, use the FGTFirewallAddress suffix with the corresponding verb:

    • Get-FGTFirewallAddress
    • Add-FGTFirewallAddress
    • Copy-FGTFirewallAddress
    • Set-FGTFirewallAddress
    • Remove-FGTFirewallAddress

    Supported Resource Types include:

    • Network: Address, AddressGroup, Interface, IP Pool, Static Route, Virtual IP, Virtual IP Group, Zone, SD-WAN.
    • Routing: BGP, OSPF, RoutePolicy.
    • Security: Policy, Local In Policy, Proxy (Address/Group/Policy), Security Profiles, Web Filter, VPN IPsec (Phase 1/2), VPN SSL, ZTNA.
    • System: System Admin, System Global, System Settings, VDOM, HA, DNS, DHCP Server.
    • Users: User LDAP, User Local, User Group, User RADIUS, User TACACS, User SAML.
    • Other: SDN Connector, Service Custom, Service Group, Switch/Controller, Wireless, Log Traffic/Event, Monitor.
  2. Configure different types of static routes

    master

    The Add-FGTRouterStatic cmdlet uses different parameter sets to define the type of route being created. You must provide the required parameters specific to the desired routing behavior:

    Standard Route via Device

    Requires -dst (destination) and -device (interface).

    Blackhole Route

    Requires -dst and the -blackhole switch. This is used to drop traffic to a specific destination.

    ISDB (Internet Service Database) Routes

    Used for routing based on predefined internet services.

    • ISDB via Device: Requires -device and -internet_service (ID).
    • ISDB Blackhole: Requires -internet_service (ID) and the -blackhole switch.

    Destination Address Routes

    • dstaddr_device: Requires -dstaddr, -device, and optionally -blackhole.
    • dstaddr_blackhole: Requires -dstaddr and the -blackhole switch.
  3. Manage VDOMs in PowerFGT

    master

    PowerFGT allows you to target specific Virtual Domains (VDOMs) using the -vdom parameter on most cmdlets. By default, the root VDOM is used.

    Usage Patterns:

    • Single VDOM: Get-FGTFirewallAddress -vdom vdomX
    • Multiple specific VDOMs: Get-FGTFirewallAddress -vdom vdomX,root
    • All VDOMs: Get-FGTFirewallAddress -vdom *

    Connection Settings:

    • Set the default VDOM during connection: Connect-FGT <IP> -vdom vdomX
    • Change the default VDOM for an existing connection: Set-FGTConnection -vdom vdomY
    Get-FGTFirewallAddress -vdom vdomX
  4. Execute individual PowerFGT tests

    master

    Tests are organized by functional area. You can run specific test files or target specific test names within a file to save time.

    Run all tests in a specific functional file:

    Invoke-Pester Connection.Tests.ps1

    Run a specific test case within a file: Use the -testName parameter to target a specific Describe block or test name.

    Invoke-Pester Connection.Tests.ps1 -testName "Connect to a FortiGate (using HTTP)"
  5. Update FortiGate Local User contact information

    master

    You can update contact details such as email or SMS phone numbers using the following parameters:

    • -email_to <String>: Sets the user's email address.
    • -sms_phone <String>: Sets the user's SMS phone number (can also be set via the -data hashtable).
    • -data <Hashtable>: Used for arbitrary data updates, such as @{ "sms-phone" = "XXXXXXXXXX" }.
    # Set email
    $MyFGTUserLocal | Set-FGTUserLocal -email_to newpowerfgt@fgt.power
    
    # Set SMS via hashtable
    $data = @{ "sms-phone" = "XXXXXXXXXX" }
    $MyFGTUserLocal | Set-FGTUserLocal -data $data
  6. Manage FortiGate Virtual IP Groups

    master

    Virtual IP Groups allow you to group multiple Virtual IPs. You can manage them using:

    • Add-FGTFirewallVIPGroup: Create a new VIP group.
    • Get-FGTFirewallVIPGroup: Retrieve VIP group information.
    • Set-FGTFirewallVIPGroup: Modify properties.
    • Copy-FGTFirewallVIPGroup: Clone a group.
    • Add-FGTFirewallVIPGroupMember: Add a member (VIP) to the group.
    • Remove-FGTFirewallVIPGroupMember: Remove a member from the group.
    • Remove-FGTFirewallVIPGroup: Delete the group.
    # Add a VIP Group with myVIP1 and myVIP2
    Add-FGTFirewallVIPGroup -name "MyVIPGroup" -member myVIP1, myVIP2
    
    # Add myVIP3 to an existing group
    Get-FGTFirewallVIPGroup -name "MyVIPGroup" | Add-FGTFirewallVIPGroupMember -member myVIP3
    
    # Remove myVIP2 from an existing group
    Get-FGTFirewallVIPGroup -name "MyVIPGroup" | Remove-FGTFirewallVIPGroupMember -member myVIP2
    
    # Modify a VIP Group
    Get-FGTFirewallVIPGroup -name "MyVIPGroup" | Set-FGTFirewallVIPGroup -comment "Updated comment" -member myVIP2
    
    # Remove a VIP Group
    Get-FGTFirewallVIPGroup -name "MyVIPGroup" | Remove-FGTFirewallVIPGroup
  7. Get Switch Group metadata and schema

    master

    Use the following flags to change the output format:

    • -meta: Returns the Switch Group object along with metadata (e.g., q_ref for usage).
    • -schema: Returns the schema definition of the Switch Group instead of the object list.
    • -skip: Returns only the relevant attributes of the objects, ignoring non-essential data.
    Get-FGTSwitchGroup -meta
    Get-FGTSwitchGroup -schema
    Get-FGTSwitchGroup -skip
  8. Manage multiple FortiGate connections simultaneously

    master

    Since version 0.3.0, PowerFGT supports MultiConnection. You can maintain separate connection objects for multiple FortiGate devices and target them individually using the -connection parameter.

    Workflow:

    1. Connect to each device using Connect-FGT with -DefaultConnection:$false to prevent them from overwriting the global default connection.
    2. Store the returned connection objects in variables.
    3. Pass the variable to cmdlets using the -connection parameter.

    Example:

    # Connect to two different FortiGates
    $fw1 = Connect-FGT 192.0.2.1 -SkipCertificateCheck -DefaultConnection:$false
    $fw2 = Connect-FGT 192.0.2.2 -SkipCertificateCheck -DefaultConnection:$false
    
    # Retrieve interfaces from the first device
    Get-FGTSystemInterface -connection $fw1 | Format-Table
    
    # Retrieve interfaces from the second device
    Get-FGTSystemInterface -connection $fw2 | Format-Table
  9. Manage FortiGate Virtual IPs (VIP)

    master

    Virtual IPs (VIPs) are used for NAT configurations. You can manage them using:

    • Add-FGTFirewallVip: Create a new VIP.
    • Get-FGTFirewallVip: Retrieve VIP information.
    • Remove-FGTFirewallVip: Delete a VIP.

    Common configurations include static-nat and port forwarding.

    # Add a basic Static NAT VIP (192.2.0.1 => 198.51.100.1)
    Add-FGTFirewallVip -name myVIP1 -type static-nat -extip 192.2.0.1 -mappedip 198.51.100.1
    
    # Add a Static NAT VIP with Port Forwarding (192.2.0.2:8080 => 198.51.100.2:80)
    Add-FGTFirewallVip -name myVIP2-8080to80 -type static-nat -extip 192.2.0.2 -mappedip 198.51.100.2 -portforward -extport 8080 -mappedport 80
    
    # Remove a VIP
    Get-FGTFirewallVip -name myVIP1 | Remove-FGTFirewallVip