Printserver Migration Part #3: Import TCP- und LPR-Ports

Ich stelle hier ein paar Skripte zur Verfügung, welche einem die Migration eines Printservers etwas vereinfachten. Selbstverständlich kann man das auch mir Printmig oder anderen Tools durchführen. Ich wollte meinen neuen Printserver from scratch neu installieren, daher der etwas andere Weg. Die Migration wird in vier Teile erfolgen:

Part #1: Export TCP- und LPR-Ports
Part #2: Export Drucker mit allen Settings in eine XML-Datei
Part #3: Import TCP- und LPR-Ports
Part #4: Import aller Drucker mit allen Settings

Part #3: Import TCP- und LPR-Ports
Jetzt können wir die TCP- und LPR-Ports auf dem neuen Printserver erstellen lassen.
Auch hier gibt es wieder zwei Skripte, da TCP-Ports anders erzeugt werden als LPD-Ports.
ACHTUNG: Vor der Erstellung der LPR-Ports muss der LPD-Service erst über den Servermanager installiert werden, damit der LPR-Porttype zur Verfügung steht.
TIPP: Sollten die Namen oder die IPs der Ports geändert werden, dann bitte vorher in der CSV anpassen!

Create-Printerports_TCP_from_CSV.ps1
<# 
.NAME
    Create-Printerports_TCP_from_CSV.ps1

.AUTHOR
    Ralf Entner

.SYNOPSIS
    Script creates all TCP Printer Ports from a csv file.

.DESCRIPTION 
    Script creates all TCP Printer Ports with all settings from a csv file. In the csv file there are address, port number and smtp settings.
 
.NOTES 
    With the testmode $true you can run the script without any changes. It will only show whatif

.COMPONENT 
    No powershell modules needed

.LINK 
    No Links
 
.Parameter ParameterName 
    $CSVPath - Define import path of the csv file
    $Testmode - Defines testmode: $true = test | $false = live
#>

$CSVPath = "C:\tgswinv\Printmig\PortsTCP.csv"
$Testmode = $false

# Import CSV with Port Informations
$PrinterPorts = Import-CSV -Path $CSVPath -Delimiter ";"

# Loop through 
Foreach($Port in $PrinterPorts){

Write-Host "Creating Printerport $Name"

# Check if Printerport already exists
if(!(Get-PrinterPort -Name $Port.Name -ErrorAction SilentlyContinue))
    {
        Add-PrinterPort -Name $Port.Name -PrinterHostAddress $Port.PrinterHostAddress -PortNumber $Port.Portnumber -SNMPCommunity $Port.SNMPCommunity -SNMP $true -WhatIf:$Testmode
    }
}

Create-Printerports_LPR_from_CSV.ps1
<# 
.NAME
    Create-Printerports_LPR_from_CSV.ps1

.AUTHOR
    Ralf Entner

.SYNOPSIS
    Script creates all LPR Printer Ports from a csv file.

.DESCRIPTION 
    Script creates all LPR Printer Ports with all settings from a csv file.
    In the csv file there are name, protocol, port nubmer and printer host address.
 
.NOTES 
    With the testmode $true you can run the script without any changes. It will only show whatif

.COMPONENT 
    ATTENTION: You have to install the LPR printer monitor before you add the ports!
    No powershell modules needed

.LINK 
    No Links
 
.Parameter ParameterName 
    $CSVPath - Define import path of the csv file
    $Testmode - Defines testmode: $true = test | $false = live
#>

$CSVPath = "C:\tgswinv\Printmig\PortsLPR.csv"
$Testmode = $false

# Import CSV with Port Informations
$PrinterPorts = Import-CSV -Path $CSVPath -Delimiter ";"

# Loop through 
Foreach($Port in $PrinterPorts){

Write-Host "Creating Printerport "$Port.Name

# Check if Printerport already exists
if(!(Get-PrinterPort -Name $Port.Name -ErrorAction SilentlyContinue))
    {
        #Add-PrinterPort -Name $Port.PrinterName -PrinterHostAddress $Port.hostname -WhatIf:$Testmode
        Add-PrinterPort -PrinterName $Port.Printername -HostName $port.Hostname   -WhatIf:$Testmode
    }
}



Printserver Migration Part #2: Export Printer and Printer Settings

Ich stelle hier ein paar Skripte zur Verfügung, welche einem die Migration eines Printservers etwas vereinfachten. Selbstverständlich kann man das auch mir Printmig oder anderen Tools durchführen. Ich wollte meinen neuen Printserver from scratch neu installieren, daher der etwas andere Weg. Die Migration wird in vier Teile erfolgen:

Part #1: Export TCP- und LPR-Ports
Part #2: Export Drucker mit allen Settings in eine XML-Datei
Part #3: Import TCP- und LPR-Ports
Part #4: Import aller Drucker mit allen Settings

Part #2: Export Drucker mit allen Settings in eine XML-Datei
Mit dem nachfolgenden Skript erfolgt der Export aller installierten Drucker, welche Netzwerkdrucker sind. Es wird eine CSV mit den grundlegenden Druckerinformationen erstellt. Außerdem wird für jeden Drucker die Konfiguration in eine XML-Datei exportiert, welche die komplette Konfiguration der Schächte und Papierquellen etc. enthält. Mit diesen Informationen können später die Drucker vollständig auf dem neuen Server wiederhergestellt werden.

Export-Printer_and_Printerconfiguration.ps1
<# 
.NAME
    Export-Printer_and_Printerconfiguration.ps1

.AUTHOR
    Ralf Entner

.SYNOPSIS
    Script exports all network printers and printer settings.

.DESCRIPTION 
    Script exports all network Printers with all settings to a single csv file.
    The printer configurations are also exported in a xml file for each printer name (printername.xml)
    The export includes name, shared name, port name, driver name, location, comment und publishing information.

.NOTES 
    The script exports only network printers.

.COMPONENT 
    No powershell modules needed

.LINK 
    No Links
 
.Parameter ParameterName 
    $CSVPath - Define export path of the csv file
    $XMLPath - Define export path of xml file for each printer configuration
#>
# Export CSV path
$CSVPath = "C:\Printmig\Printers.csv"
$XMLPath = "C:\Printmig\"

# Get all printers and informtaions
$Printers = Get-Printer | ?{$_.PortName -ne "PORTPROMPT:"} | select Name, ShareName, PortName, DriverName, Location, Comment, Published, Shared

# Export Printers to csv
$Printers | Export-Csv -Path $CSVPath -Delimiter ";" -Encoding UTF8 -NoTypeInformation

Foreach ($Printer in $Printers){

    #Exportpaht for XML

    $XMLFilePath = $XMLPath + $Printer.Name + ".xml"

    # Export PrinterConfiguration to XML
    $GPC = get-printconfiguration -PrinterName $Printer.Name
    $GPC.PrintTicketXML | out-file $XMLFilePath
}

“Das einzig sichere System müsste ausgeschaltet, in einem versiegelten und von Stahlbeton ummantelten Raum und von bewaffneten Schutztruppen umstellt sein.”
Gene Spafford (Sicherheitsexperte)