mirror of
https://github.com/freedbygrace/PSOPNSenseAPI.git
synced 2026-07-26 11:58:18 +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:
@@ -0,0 +1,76 @@
|
||||
# Export-OPNSenseConfig
|
||||
|
||||
## SYNOPSIS
|
||||
Exports the OPNSense firewall configuration.
|
||||
|
||||
## SYNTAX
|
||||
|
||||
```
|
||||
Export-OPNSenseConfig -Path <FileInfo> [-Force]
|
||||
```
|
||||
|
||||
## DESCRIPTION
|
||||
The Export-OPNSenseConfig cmdlet exports the OPNSense firewall configuration to a file.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
### Example 1: Export the configuration to a file
|
||||
```powershell
|
||||
$path = New-Object System.IO.FileInfo "C:\Backups\opnsense-config.xml"
|
||||
Export-OPNSenseConfig -Path $path
|
||||
```
|
||||
|
||||
This example exports the OPNSense firewall configuration to a file.
|
||||
|
||||
## PARAMETERS
|
||||
|
||||
### -Path
|
||||
The path to save the configuration file. Must be a FileInfo object with an .xml extension.
|
||||
|
||||
```yaml
|
||||
Type: FileInfo
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 0
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Force
|
||||
Overwrites the file if it exists.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### CommonParameters
|
||||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
|
||||
|
||||
## INPUTS
|
||||
|
||||
### None
|
||||
|
||||
## OUTPUTS
|
||||
|
||||
### None
|
||||
|
||||
## NOTES
|
||||
This cmdlet requires a connection to an OPNSense firewall. Use Connect-OPNSense to establish a connection.
|
||||
If the directory specified in the Path parameter does not exist, it will be created.
|
||||
|
||||
## RELATED LINKS
|
||||
|
||||
[Get-OPNSenseConfig](Get-OPNSenseConfig.md)
|
||||
[Import-OPNSenseConfig](Import-OPNSenseConfig.md)
|
||||
[Restore-OPNSenseConfig](Restore-OPNSenseConfig.md)
|
||||
@@ -0,0 +1,52 @@
|
||||
# Get-OPNSenseConfig
|
||||
|
||||
## SYNOPSIS
|
||||
Gets the OPNSense firewall configuration as an XML document.
|
||||
|
||||
## SYNTAX
|
||||
|
||||
```
|
||||
Get-OPNSenseConfig
|
||||
```
|
||||
|
||||
## DESCRIPTION
|
||||
The Get-OPNSenseConfig cmdlet retrieves the OPNSense firewall configuration and returns it as an XML document.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
### Example 1: Get the configuration as an XML document
|
||||
```powershell
|
||||
$config = Get-OPNSenseConfig
|
||||
```
|
||||
|
||||
This example retrieves the OPNSense firewall configuration as an XML document.
|
||||
|
||||
### Example 2: Get the configuration and pipe it to Restore-OPNSenseConfig
|
||||
```powershell
|
||||
Get-OPNSenseConfig | Restore-OPNSenseConfig
|
||||
```
|
||||
|
||||
This example retrieves the OPNSense firewall configuration and restores it.
|
||||
|
||||
## PARAMETERS
|
||||
|
||||
### CommonParameters
|
||||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
|
||||
|
||||
## INPUTS
|
||||
|
||||
### None
|
||||
|
||||
## OUTPUTS
|
||||
|
||||
### System.Xml.XmlDocument
|
||||
The OPNSense configuration as an XML document.
|
||||
|
||||
## NOTES
|
||||
This cmdlet requires a connection to an OPNSense firewall. Use Connect-OPNSense to establish a connection.
|
||||
|
||||
## RELATED LINKS
|
||||
|
||||
[Restore-OPNSenseConfig](Restore-OPNSenseConfig.md)
|
||||
[Export-OPNSenseConfig](Export-OPNSenseConfig.md)
|
||||
[Import-OPNSenseConfig](Import-OPNSenseConfig.md)
|
||||
@@ -0,0 +1,106 @@
|
||||
# Import-OPNSenseConfig
|
||||
|
||||
## SYNOPSIS
|
||||
Imports an OPNSense firewall configuration.
|
||||
|
||||
## SYNTAX
|
||||
|
||||
```
|
||||
Import-OPNSenseConfig -Path <FileInfo> [-Force] [-WhatIf] [-Confirm]
|
||||
```
|
||||
|
||||
## DESCRIPTION
|
||||
The Import-OPNSenseConfig cmdlet imports an OPNSense firewall configuration from a file.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
### Example 1: Import a configuration from a file
|
||||
```powershell
|
||||
$path = New-Object System.IO.FileInfo "C:\Backups\opnsense-config.xml"
|
||||
Import-OPNSenseConfig -Path $path
|
||||
```
|
||||
|
||||
This example imports an OPNSense firewall configuration from a file.
|
||||
|
||||
## PARAMETERS
|
||||
|
||||
### -Path
|
||||
The path to the configuration file. Must be a FileInfo object with an .xml extension.
|
||||
|
||||
```yaml
|
||||
Type: FileInfo
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 0
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Force
|
||||
Suppresses the confirmation prompt.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -WhatIf
|
||||
Shows what would happen if the cmdlet runs. The cmdlet is not run.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases: wi
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Confirm
|
||||
Prompts you for confirmation before running the cmdlet.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases: cf
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### CommonParameters
|
||||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
|
||||
|
||||
## INPUTS
|
||||
|
||||
### None
|
||||
|
||||
## OUTPUTS
|
||||
|
||||
### None
|
||||
|
||||
## NOTES
|
||||
This cmdlet requires a connection to an OPNSense firewall. Use Connect-OPNSense to establish a connection.
|
||||
The firewall will restart after the configuration is imported.
|
||||
|
||||
## RELATED LINKS
|
||||
|
||||
[Get-OPNSenseConfig](Get-OPNSenseConfig.md)
|
||||
[Export-OPNSenseConfig](Export-OPNSenseConfig.md)
|
||||
[Restore-OPNSenseConfig](Restore-OPNSenseConfig.md)
|
||||
@@ -0,0 +1,142 @@
|
||||
# Restore-OPNSenseConfig
|
||||
|
||||
## SYNOPSIS
|
||||
Restores an OPNSense firewall configuration.
|
||||
|
||||
## SYNTAX
|
||||
|
||||
### Filename
|
||||
```
|
||||
Restore-OPNSenseConfig -Filename <String> [-Force] [-WhatIf] [-Confirm]
|
||||
```
|
||||
|
||||
### XmlDocument
|
||||
```
|
||||
Restore-OPNSenseConfig -XmlDocument <XmlDocument> [-Force] [-WhatIf] [-Confirm]
|
||||
```
|
||||
|
||||
## DESCRIPTION
|
||||
The Restore-OPNSenseConfig cmdlet restores an OPNSense firewall configuration from a backup or an XML document.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
### Example 1: Restore a configuration backup
|
||||
```powershell
|
||||
Restore-OPNSenseConfig -Filename "config-backup-20250414-1234.xml"
|
||||
```
|
||||
|
||||
This example restores an OPNSense firewall configuration from a backup file.
|
||||
|
||||
### Example 2: Restore a configuration from an XML document
|
||||
```powershell
|
||||
$config = Get-OPNSenseConfig
|
||||
Restore-OPNSenseConfig -XmlDocument $config
|
||||
```
|
||||
|
||||
This example restores an OPNSense firewall configuration from an XML document.
|
||||
|
||||
### Example 3: Restore a configuration from the pipeline
|
||||
```powershell
|
||||
Get-OPNSenseConfig | Restore-OPNSenseConfig
|
||||
```
|
||||
|
||||
This example restores an OPNSense firewall configuration from the pipeline.
|
||||
|
||||
## PARAMETERS
|
||||
|
||||
### -Filename
|
||||
The filename of the backup to restore.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: Filename
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 0
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -XmlDocument
|
||||
The XML document containing the configuration to restore.
|
||||
|
||||
```yaml
|
||||
Type: XmlDocument
|
||||
Parameter Sets: XmlDocument
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 0
|
||||
Default value: None
|
||||
Accept pipeline input: True (ByValue)
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Force
|
||||
Suppresses the confirmation prompt.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -WhatIf
|
||||
Shows what would happen if the cmdlet runs. The cmdlet is not run.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases: wi
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Confirm
|
||||
Prompts you for confirmation before running the cmdlet.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases: cf
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### CommonParameters
|
||||
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
|
||||
|
||||
## INPUTS
|
||||
|
||||
### System.Xml.XmlDocument
|
||||
An XML document containing the OPNSense configuration.
|
||||
|
||||
## OUTPUTS
|
||||
|
||||
### None
|
||||
|
||||
## NOTES
|
||||
This cmdlet requires a connection to an OPNSense firewall. Use Connect-OPNSense to establish a connection.
|
||||
The firewall will restart after the configuration is restored.
|
||||
|
||||
## RELATED LINKS
|
||||
|
||||
[Get-OPNSenseConfig](Get-OPNSenseConfig.md)
|
||||
[Export-OPNSenseConfig](Export-OPNSenseConfig.md)
|
||||
[Import-OPNSenseConfig](Import-OPNSenseConfig.md)
|
||||
@@ -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