Forum Discussion
Help with Powershell scripts to backup and restore printers
here is the refined version of your scripts
<#
.SYNOPSIS
Copies an existing printer to a new printer with a different name and IP address.
... (rest of your synopsis and description)
#>
param (
[Parameter(Mandatory = $true)]
[string]$ExistingPrinterName,
[Parameter(Mandatory = $true)]
[string]$NewPrinterName
)
# Load Settings - Dynamic Path Resolution
$settingsPath = Resolve-Path (Join-Path $PSScriptRoot "settings.ps1")
. $settingsPath # Dot-source the settings file
# Error Handling for Missing Settings
if (-not $BaseFolder) {
Write-Error "ERROR: BaseFolder is not defined in settings.ps1"
exit 1
}
# Function Auto-Loading
$requiredFunctions = "Backup-SinglePrinter", "Restore-SinglePrinter", "Find-AvailableIPPort", "Get-PrinterExtendedConfig"
foreach ($func in $requiredFunctions) {
if (-not (Get-Command -Name $func -ErrorAction SilentlyContinue)) {
$modulePath = Resolve-Path (Join-Path $BaseFolder "$func.psm1")
Import-Module $modulePath -Force
}
}
try {
# Backup and Restore Logic (Unchanged)
# ... (your existing backup and restore code)
} catch {
# Error Handling and Cleanup (Unchanged)
# ... (your existing error handling and cleanup code)
}
sdtslmn Sorry for taking so long to get back to you. I refined my requirements to perfectly clone one of the installed printers (from a numbered list on screen) to a new printer with a new name, sharename, IP address and every possible setting/property/detail, regardless of printer make/model. I've got some of it working, but the detailed copy is not working. The IP address should start at 132.147.162.254 (the original printer's IP). I would like the script to offer a derivative of the existing IP such as 132.147.162.254_1 or whichever such IP is not in use. It should not make 132.147.162.254_1_2.
I'm still a powershell noob, and the A.I. is not as good as I hoped. I keep telling it to add Write-Host modulename at the top of the scripts, but it forgets. Funnier than that, it just reminded me that we should do that, as if it was not my idea in the first place.
Care to take a look?
Mike