mirror of
https://github.com/freedbygrace/PSOPNSenseAPI.git
synced 2026-08-08 01:43:22 +00:00
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
This commit is contained in:
@@ -8,22 +8,29 @@ Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -
|
||||
$backups = Get-OPNSenseConfigBackup
|
||||
$backups | Format-Table -Property Filename, Description, FileSize, Date, Version
|
||||
|
||||
# Create a new configuration backup
|
||||
$backupFilename = Backup-OPNSenseConfig -Filename "pre-upgrade-backup"
|
||||
Write-Output "Created backup: $backupFilename"
|
||||
# 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 = "C:\Backups\opnsense-config.xml"
|
||||
$exportPath = New-Object System.IO.FileInfo "C:\Backups\opnsense-config.xml"
|
||||
Export-OPNSenseConfig -Path $exportPath -Force
|
||||
Write-Output "Exported configuration to: $exportPath"
|
||||
Write-Output "Exported configuration to: $($exportPath.FullName)"
|
||||
|
||||
# Import a configuration from a file
|
||||
# Note: This will restart the firewall
|
||||
# Import-OPNSenseConfig -Path $exportPath -Confirm
|
||||
# Import-OPNSenseConfig -Path $exportPath -Force
|
||||
|
||||
# Restore a configuration backup
|
||||
# Restore a configuration backup by filename
|
||||
# Note: This will restart the firewall
|
||||
# Restore-OPNSenseConfig -Filename $backupFilename -Confirm
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user