Powershell – printer migration installation script

Hi All,

I’m showing you a script to install / migrate printers from a print server
Juste before use the script, you must :
1 – install all driver you need
2 – fill the printer.csv file with all the information. (use an extract from your current server for exemple)

The script have two function :
1 – create all the printer port
2 – install all the printer
3 – print test page spooler
Take care about the Printer Driver Name ! it’s important !


the file here : printer.csv

 

Import-Module ServerManager
$folder = split-path $myinvocation.mycommand.path
Get-Content -Path $Chemin\printer.csv | Out-File -FilePath $folder\printer-unicode.csv -Encoding Unicode
$Printers_SRV=Import-Csv -Delimiter ";" -path "$folder\printer-unicode.csv"

function create-port
{ 
Param ( $Srv = "." , $PortName , $TCPIP , $Prot = 1, $PortNum = "9100", $Snmp= $false) 
$port =[WMICLASS]"Win32_TcpIpPrinterPort"
$newport= $port.createInstance() 
$newport.name = $PortName
$newport.Protocol = $Prot
$newport.HostAddress = $TCPIP
$newport.PortNumber = $PortNum
$newport.SnmpEnabled = $Snmp

$newport.Put() 
}

function Create-Printer 
{ 
Param ( $Srv = ".", $deviceID, $drv32 , $PortName, $Shared= $true, $ShareName , $Loc, $Comment ) 
$print = ([WMICLASS]"\\$Srv\ROOT\cimv2:Win32_Printer").createInstance()
$print.DeviceID = $deviceID
$print.drivername = $drv32
$print.PortName = $PortName
$print.Shared = $Shared
$print.Sharename = $ShareName
$print.Location = $Loc
$print.Comment = $Comment

$print.Put()
}

Foreach ($Port_SRV in $Printers_SRV)
{
#définition de la variable nom du port
$PortName = $Port_SRV.PortName
#définition de la variable IP
$TCPIP = $Port_SRV.IP
create-port -PortName "$PortName" -TCPIP "$TCPIP"
}

Foreach ($Printer_SRV in $Printers_SRV)
{
#définition de la variable nom 
$deviceID = $Printer_SRV.PrinterName

#définition de la variable drivers
$drv32 = $Printer_SRV.DriverName

#définition de la variable port
$PortName = $Printer_SRV.PortName

#définition de la variable nom de partage
$ShareName = $Printer_SRV.ShareName

#définition de la variable localisation
$Loc = $Printer_SRV.Emplacement

#définition de la variable commentaire
$Comment = $Printer_SRV.Commentaires

create-printer -deviceID "$deviceID" -drv32 "$drv32" -PortName "$PortName" -ShareName "$ShareName" -Loc "$Loc" -Comment "$Comment"
}

1 commentaire sur “Powershell – printer migration installation script”

  1. Ping : Powershell – Printer Server – Spooling Test Page to Printer – People Are Geek

Laisser un commentaire