CSV Format:
Printserver,drivername,PortName,IPAddress,Sharename,Location,Comment,Printername
XXX,HP Test,IP_x.x.x.x,x.x.x.x,printername,location test,comment test,printernameScript:
function CreatePrinter {
$server = $args[0]
$print.drivername = $args[1]
$print.PortName = $args[2]
$print.Shared = $true
$print.Sharename = $args[3]
$print.Location = $args[4]
$print.Comment = $args[5]
$print.DeviceID = $args[6]
$print.Put()
}
function CreatePrinterPort {
$server = $args[0]
$port.Name= $args[1]
$port.SNMPEnabled=$false
$port.Protocol=1
$port.HostAddress= $args[2]
$port.Put()
}
$printers = Import-Csv c:\printers.csv
foreach ($printer in $printers) {
CreatePrinterPort $printer.Printserver $printer.Portname
$printer.IPAddress
CreatePrinter $printer.Printserver $printer.drivername
$printer.Portname $printer.Sharename $printer.Location $printer.Comment
$printer.Printername
}
Many thanks for this brilliant post! Many points have extremely useful. Hopefully you'll continue sharing your knowledge around.
ReplyDeletedrukarka 3d
Hi Peter
DeleteCan you please share the screen shot of how csv file fields are filled.
$ printers = Import-Csv c:\users\Michel.aras\desktop\printers.csv
ReplyDeletedoes not work
This is a fantastic post! The PowerShell script for adding printers from a CSV file is a real time-saver, especially for administrators managing multiple devices in large environments. Automating printer deployment can significantly reduce errors and improve efficiency, so I appreciate the detailed explanation and script example you've provided.
ReplyDeleteOne question: Do you have any recommendations for handling scenarios where a printer driver isn’t pre-installed on the machine? It would be great to hear your insights on incorporating driver installation into the script.
Thank you for sharing such practical and valuable content!
Epicforce Tech