Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1374
  • Last Modified:

Script to create printer on windows 2k8 cluster

I have a cluster Windows 2k8 and I have to create 2000 printers on it. I've found a powershell script =>
Snippet ID=476535

the problem is that the printer is created on one node and not the cluster instance. I have read some articles about use wmi object on a cluster environnement ( \\<YourClusterName>\root\mscluster ) but I don't know how to modify my script to be compatible with cluster environnement.

Thanks


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.Put() 
}

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() 
}

CreatePrinterPort nrbnrw90z nrbp0105 nrbp0105
CreatePrinter nrbnrw90z "HP LaserJet 4250 PCL 5" nrbp0105 nrbp0105 TESTING TESTING nrbp0105

Open in new window

0
nrbasw
Asked:
nrbasw
  • 4
  • 3
1 Solution
 
gtworekCommented:
Use cluster resource WMI class (http://msdn.microsoft.com/en-us/library/aa371464(VS.85).aspx) not server one.
You can also use "cluster.exe" command with "resource" parameter. Look at http://technet.microsoft.com/en-us/library/cc785087(WS.10).aspx
0
 
nrbaswAuthor Commented:
I have read this link http://msdn.microsoft.com/en-us/library/aa371464(VS.85).aspx and modify line 3 of my script like that :
$print = ([WMICLASS]"\\$server\ROOT\mscluster :Win32_Printer").createInstance()

but it return me this message :
Cannot convert value "\\nrbnrw90z\ROOT\mscluster :Win32_TCPIPPrinterPort" to ty
pe "System.Management.ManagementClass". Error: "Invalid parameter "

Could you tel how can I adapt my script to work with clustered environnement ?

Thanks a lot
0
 
gtworekCommented:
Did you use your node or your cluster name as $server ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
nrbaswAuthor Commented:
It's the cluster name : nrbnrw90z
node one is nrbnrw90a
node two is nrbnrw90b

0
 
gtworekCommented:
Do you use space between "mscluster" and ":Win32_TCPIPPrinterPort"? There's no space!
You can also try with
$printer = new-object system.management.ManagementClass "\\$server\ROOT\mscluster:Win32_Printer"
0
 
nrbaswAuthor Commented:
Thank for your answer...

Do you use space between "mscluster" and ":Win32_TCPIPPrinterPort"? There's no space!


I try without space but it doesn't change anything.

$printer = new-object system.management.ManagementClass "\\$server\ROOT\mscluster:Win32_Printer"

I test that in a terminal and  i have the following message :

New-Object : Exception retrieving the type name hierarchy: "Not found ".
At line:1 char:19c + $test = new-object  <<<< system.management.ManagementClass "\\nrbnrw90z\ROOT\mscluster:Win32_Printer"

I've found a answer here : http://www.eggheadcafe.com/software/aspnet/30327294/win32process-type-name-n.aspx

but I don't know if it advisable to apply this solution ?

0
 
DIT_ExpertsCommented:
Hi,
I have a hard time finding your 'solution' in the posted link. Did you end out being able to create those print ports on the clustered print server?

Thanks for your help,
Tom
0
 
nrbaswAuthor Commented:
Hello,

Finally to get to my goal I created the script with my printers on a windows 2008 standalone and then I've use the print migrator tools to create it on the clustered environnement.

Thanks
0

Featured Post

Who's Defending Your Organization from Threats?

Protecting against advanced threats requires an IT dream team – a well-oiled machine of people and solutions working together to defend your organization. Download our resource kit today to learn more about the tools you need to build you IT Dream Team!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now