header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Creating printer ports
Last Post 26 Aug 2008 11:02 PM by glnsize. 7 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Ambika22User is Offline
New Member
New Member
Posts:3

--
25 Aug 2008 05:22 PM  

Hi all,

I want to create printer ports on a Windows 2003 Server using powershell. I have a spreadsheet with a list of all the printer names, port names, IP address etc.

How do I write a powershell script so that it reads this spreadsheet and automatically creates/configures the printer ports?

Kindly guide me...

 

glnsizeUser is Online
New Member
New Member
Posts:84

--
25 Aug 2008 09:34 PM  

This sounds more like a migration then a new server... If so have you looked at Print Migrator 3.x.  I don’t know how I ever lived without it.

http://www.microsoft.com/windowsserver2003/techinfo/overview/printmigrator3.1.mspx

If your not migrating but instead adding new.  It can be done via WMI using Win32_TCPIPPrinterPort, and Win32_PrinterDriver. I’ve done it before with VBScript, and It’s not fun.  I’ll dig through my scripts and see if I can find / translate later…


~Glenn

Ambika22User is Offline
New Member
New Member
Posts:3

--
25 Aug 2008 09:47 PM  

Thats right... Its a migration...

But I'm not sure how the migrator will serve the purpose... Coz I'm looking at having everything new on my server (new drivers, eliminate dead queues and printers that are not in the DNS)

Well, to start with one printer, I'm trying to run the following VBS code:

'*************Register prnadmin.dll file on client computer***********
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run"regsvr32 /s \\server\Folder Name\Prnadmin.dll",1,TRUE


'************** Create the port first *******************************
Set WshNetwork = WScript.CreateObject("WScript.Network")
'gets computer name
strComputer = WshNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_

'before adding printer we need to create ports that printers will use
objNewPort.Name = "xx.xx.x.xx
objNewPort.Protocol = 1
objNewPort.HostAddress = "xx.xx.x.xx"
objNewPort.SNMPEnabled = False
objNewPort.Put_


If Err <> 0 then
msgbox "Error on installation of printers."
end if

msgbox "End of installation of printers."

It gives me an error "SWbemObjectEx: Access Denied"

Can you tell me if I'm missing something in my code??

Thanks!!

ShayUser is Offline
Basic Member
Basic Member
Posts:228

--
25 Aug 2008 10:15 PM  
Do you have all the neccessaery permissions to create ports on the remote server?


Anyway, see if this works:

& regsvr32 /s "\\server\Folder Name\Prnadmin.dll"

$server = "serverName"
$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name="yourPortName"
$port.SNMPEnabled=$false
$port.Protocol=1
$port.HostAddress="xxx.xxx.xxx.xxx"
$port.Put()
$port
glnsizeUser is Online
New Member
New Member
Posts:84

--
25 Aug 2008 10:34 PM  

 

@ Ambika22, Totally understand, Shay's code does exactly the same thing as the VBScript you posted earlier.  Your  getting a WMI error with your VBS. 

Also verify that you have either the Win2k/Win2k3 resource kit installed... If memory serves Prnadmin.dll is in there.

@Shay, That's how you go a getobject in posh!  I've been quietly wondering that for a while now.

([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()

~Glenn

ShayUser is Offline
Basic Member
Basic Member
Posts:228

--
25 Aug 2008 10:44 PM  
BTW, you can get the same with:

$port = (gwmi -list -computer . | where {$_.name -eq 'Win32_TCPIPPrinterPort'}).createInstance()

But I like better using the [WMICLASS] type accelerator ;-)
Ambika22User is Offline
New Member
New Member
Posts:3

--
26 Aug 2008 03:18 PM  

 

Well, I have Windows Resource Kit on the remote server and I also have the necessary permissions to create ports on the remote server.

I'm remotely logging in to the server and running the script which Shay had mentioned earlier


& regsvr32 /s "\\ServerA\Print Cluster Replacement Project\Scripts\Prnadmin.dll"

$server = "serverA"
$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name="yourPortName"
$port.SNMPEnabled=$false
$port.Protocol=3
$port.HostAddress="xxx.xxx.xxx.xxx"
$port.Put()
$port

Well what does the host address have to be in this case?

What does port protocol = 1 or 2 or 3 mean

Also, it gives me an error with the put() statement

I'm actually very new to this domain, and as such have a lot of questions on mind

Kindly help me out with this

 

Thanks and regards,

Ambika

glnsizeUser is Online
New Member
New Member
Posts:84

--
26 Aug 2008 11:02 PM  

hmm, well there isn't a protocol 3... Your .put() is most likely failing because your attempting to set an illegal value. 

When you don't know what a particular property is setting, or as in this case don't know the options, and there meaning.  MSDN is your friend... I've been using it for YEARS with WMI, and now use it for .net as well. 

Anyways MSDN says:

1 = RAW, Printing directly to a device or print server.
2=LPR, Legacy protocol, which is eventually replaced by RAW.

you can find it all here.

Hope that helps

~Glenn

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer