Not sure if this sis the correct place to do this.
I have a script to add multiple printers & ports from a csv file and this seems to work well for my 2003 servers. However it seems completely broken when running against a 2012 box. I would like to know what code I need to use to run this on/against a 2012 machine. Even running this script ON 2003 AGAINST 2012 fails.
Here is the code from the current script:
$Source = "\\ExecutingServer\PrinterChanges"#-----Create object to use data in the csv file-----#
$printers = Import-Csv $Source\printers.csv#-----create function block to (RE)CREATE the PORT to be used by the printer-----#
function CreatePrinterPort
{
$server = $args[0]
$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name = $args[1]
$port.SNMPEnabled = $false
$port.Protocol = 1
$port.HostAddress = $args[2]
$port.Put()
}#-----create function block to RECREATE the PRINTER object-----#
function CreatePrinter
{
$server = $args[0]
$print = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_Printer").createInstance()
$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.Rawonly = $true
$print.DoCompleteFirst = $true
$print.Put()
}
#-----Foreach loop to Call the function blocks and declare which properties, that are outlined in the CSV, will be used by the script.-----#
foreach ($printer in $printers)
{
DeletePrinter $printer.Printserver $printer.Printername
# DeletePrinterPort $printer.Printserver $printer.Portname
CreatePrinterPort $printer.Printserver $printer.Portname $printer.HostAddress
CreatePrinter $printer.Printserver $printer.Driver $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.Printername
}
#-----END-----#
I would like to know how I can accomplish this BULK add of ports and printers in PS 3.0 Please.