i need some help migrating printers from server to another server i found a script online to migrate the printer script not working for me.
.SYNOPSIS
Logon Script to migrate printer mappings from UTILITY2012|UTILITY2012 to ICUPRTSVR01 for Windows 7 users
.DESCRIPTION
Logon Script to migrate printer mappings from UTILITY2012|UTILITY2012 to ICUPRTSVR01 for Windows 7 users
.NOTES
Author: Boe Prox
Create: 09 NOV 2012
Modified:
Version 1.0 - Initial Script Creation
1.1 Added Header Text for CSV file
#>
[cmdletbinding()]
Param (
$newPrintServer = "ICUPRTSVR01"
)
<#
#Header for CSV log file:
"COMPUTERNAME,USERNAME,PRINTERNAME,RETURNCODE-ERRORMESSAGE,DATETIME,STATUS" |
Out-File -FilePath "\\ICUPRTSVR01\C$\PrintMigration\PrintMigration.csv" -Encoding ASCII
#>
Try {
Write-Verbose ("{0}: Checking for printers mapped to old print server" -f $Env:USERNAME)
$printers = @(Get-WmiObject -Class Win32_Printer -Filter "SystemName='\\\\UTILITY2012' OR SystemName='\\\\UTILITY2012'" -ErrorAction Stop)
If ($printers.count -gt 0) {
ForEach ($printer in $printers) {
Write-Verbose ("{0}: Replacing with new print server name: {1}" -f $Printer.Name,$newPrintServer)
$newPrinter = $printer.Name -replace "UTILITY2012|UTILITY2012",$newPrintServer
$returnValue = ([wmiclass]"Win32_Printer").AddPrinterConnection($newPrinter).ReturnValue
If ($returnValue -eq 0) {
If ($printer.Default) {
#If old printer was default, set new printer as default
$defaultPrinter = $newPrinter -replace "\\",'\\'
$createdPrinter = Get-WmiObject -Class Win32_Printer -Filter "Name='$defaultPrinter'"
$createdPrinter.SetDefaultPrinter() | Out-Null
}
"{0},{1},{2},{3},{4},{5}" -f $Env:COMPUTERNAME,
$env:USERNAME,
$newPrinter,
$returnValue,
(Get-Date),
"Added Printer" | Out-File -FilePath "\\ICUPRTSVR01\c$\PrintMigration\PrintMigration.csv" -Append -Encoding ASCII
Write-Verbose ("{0}: Removing" -f $printer.name)
$printer.Delete()
"{0},{1},{2},{3},{4},{5}" -f $Env:COMPUTERNAME,
$env:USERNAME,
$printer.Name,
$returnValue,
(Get-Date),
"Removed Printer" | Out-File -FilePath "\\ICUPRTSVR01\C$\printMigration\PrintMigration.csv" -Append -Encoding ASCII
} Else {
Write-Verbose ("{0} returned error code: {1}" -f $newPrinter,$returnValue)
"{0},{1},{2},{3},{4},{5}" -f $Env:COMPUTERNAME,
$env:USERNAME,
$newPrinter,
$returnValue,
(Get-Date),
"Error Adding Printer" | Out-File -FilePath "\\ICUPRTSVR01\C$\PrintMigration\PrintMigration.csv" -Append -Encoding ASCII
}
}
}
} Catch {
"{0},{1},{2},{3},{4},{5}" -f $Env:COMPUTERNAME,
$env:USERNAME,
"WMIERROR",
$_.Exception.Message,
(Get-Date),
"Error Querying Printers" | Out-File -FilePath "\\ICUPRTSVR01\C$\PrintMigration\PrintMigration.csv" -Append -Encoding ASCII
}