1.

Solve : powershell printer question?

Answer»

Can some one please point me to an example of a Powershell script that installs a TCP/IP printer? unfortunately our department decided to stop using print servers so now we are forced to add printers using print to IP. I am looking for a script that will install a printer and use a TCP/IP port.

Thanks,
WbrostThis may help. It seems straightforward. Create instances of two WMI classes and fill in the properties with your local information.

Good luck. ok getting closer. I can get the first portion of the code to work but during the second part I get the following error message:

Exception calling "Put" with "0" ARGUMENT(s): "Generic failure "
At line:1 char:19
+ $objNewPrinter.Put <<<< ()
+ CategoryInfo : NotSpecified: ( [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

Below is the code that I am using to get this working.

$objPrint = [WMICLASS]"Win32_Printer"
$objPrint.psbase.scope.options.EnablePrivileges = $true
$objNewPrinter = $objPrint.createInstance()
$objNewPrinter.DeviceID = "Rhyne_235A_02"
$objNewPrinter.DriverName = "TOSHIBA e-STUDIO3510cSeriesPLC6"
$objNewPrinter.PortName = "Toshiba_3510C"
$objNewPrinter.Shared = $false
$objNewPrinter.Put()

thanks,
wbrostI RAN into the same problem and after some tinkering around at the Powershell command line, I suspect the problem is not with the put instruction but with the value of the properties. Specifically with the Drivername property.

It seems you can create a printer without a physical unit, but the driver needs to be INSTALLED. I was able to get this snippet to work simply by using the installed driver of a real printer on my system. Be sure the same port name USED in creating the port is used when creating the printer.

Code: [Select]# -----------------------------------------------------------------------------
# Script: PSH-WMI-setTCPIPPrinterPortInstall.ps1
# Author: Powershell Community
# Date: 02/22/2011 11:07:40
# Comments: Install a printer to TCP/IP port
# -----------------------------------------------------------------------------
#Requires -Version 2.0

$PortName = "MyPort"
$PrintDriver = "HP Deskjet 930C/932C/935C"

#Create the port
#
$objPort = [wmiclass] "Win32_TcpIpPrinterPort"
$objNewPort = $objPort.CreateInstance()

#$objNewPort.psbase.scope.options.EnablePrivileges = $False #if using W2K3 use $True
$objNewPort.Name = $PortName
$objNewPort.HostAddress = "10.10.10.10"
$objNewPort.Protocol = 1 #1=RAW (default) 2=LPR
$objNewPort.Put()

#Create the Printer
#
$printer = [wmiclass] "Win32_Printer"
$newprinter = $printer.CreateInstance()

$newprinter.DeviceID = "My New Printer" #This property req'd
$newprinter.Drivername = $PrintDriver #This property req'd
$newprinter.PortName = $PortName #This property req'd

$newprinter.Shared = $true
$newprinter.Sharename = "ShareName"
$newprinter.Location = "Office"
$newprinter.COMMENT = "Comment"
$newprinter.Put()

<#
Use Get-Member on $newprint and $objNewPort to retrieve all properties
and methods available
#>

Good luck.

Quote from: Sidewinder on March 01, 2011, 04:34:39 PM

I ran into the same problem and after some tinkering around at the Powershell command line, I suspect the problem is not with the put instruction but with the value of the properties. Specifically with the Drivername property.

It seems you can create a printer without a physical unit, but the driver needs to be installed. I was able to get this snippet to work simply by using the installed driver of a real printer on my system. Be sure the same port name used in creating the port is used when creating the printer.


If any one is having this issue you can try the neat little utility MS provides to do this. And the best part is you can point to an INF over the network. This is how I solved the issue I was having above.

C:\Users\ss947bw>pnputil /?
Microsoft PnP Utility
Usage:
------
pnputil.exe [-f | -i] [ -? | -a | -d | -e ]
Examples:
pnputil.exe -a a:\usbcam\USBCAM.INF -> Add package specified by USBCAM.INF
pnputil.exe -a c:\drivers\*.inf -> Add all packages in c:\drivers\
pnputil.exe -i -a a:\usbcam\USBCAM.INF -> Add and install driver package
pnputil.exe -e -> Enumerate all 3rd party packages
pnputil.exe -d oem0.inf -> Delete package oem0.inf
pnputil.exe -f -d oem0.inf -> Force delete package oem0.inf
pnputil.exe -? -> This usage screen


Discussion

No Comment Found