Files
PSOPNSenseAPI/docs/examples/Configuration-Management.ps1
T
GraceSolutions 68e6819131 Update configuration management cmdlets
- Added Get-OPNSenseConfig cmdlet that retrieves the OPNSense configuration as an XML document
- Updated Restore-OPNSenseConfig to accept an XML document from the pipeline or as a parameter
- Changed Export-OPNSenseConfig and Import-OPNSenseConfig to use System.IO.FileInfo for the Path parameter
- Removed Backup-OPNSenseConfig cmdlet (use Get-OPNSenseConfig instead)
- Updated documentation and examples
2025-04-15 08:53:09 -04:00

37 lines
1.3 KiB
PowerShell

# Import the module
Import-Module PSOPNSenseAPI
# Connect to the OPNSense firewall
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
# Get all configuration backups
$backups = Get-OPNSenseConfigBackup
$backups | Format-Table -Property Filename, Description, FileSize, Date, Version
# Get the current configuration as an XML document
$config = Get-OPNSenseConfig
Write-Output "Retrieved configuration with root element: $($config.DocumentElement.Name)"
# Export the configuration to a file
$exportPath = New-Object System.IO.FileInfo "C:\Backups\opnsense-config.xml"
Export-OPNSenseConfig -Path $exportPath -Force
Write-Output "Exported configuration to: $($exportPath.FullName)"
# Import a configuration from a file
# Note: This will restart the firewall
# Import-OPNSenseConfig -Path $exportPath -Force
# Restore a configuration backup by filename
# Note: This will restart the firewall
# Restore-OPNSenseConfig -Filename "config-backup-20250415-1234.xml" -Force
# Restore a configuration from an XML document
# Note: This will restart the firewall
# Restore-OPNSenseConfig -XmlDocument $config -Force
# Pipeline example: Get and restore configuration in one line
# Get-OPNSenseConfig | Restore-OPNSenseConfig -Force
# Disconnect from the firewall
Disconnect-OPNSense