Script to create printer on windows 2k8 cluster

Posted on 2010-01-06
Last Modified: 2012-06-27
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.


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]

function CreatePrinterPort {
$server =  $args[0] 
$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance() 
$port.Name= $args[1]
$port.HostAddress= $args[2] 

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

Open in new window

Question by:nrbasw
    LVL 26

    Expert Comment

    Use cluster resource WMI class ( not server one.
    You can also use "cluster.exe" command with "resource" parameter. Look at

    Author Comment

    I have read this link 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
    LVL 26

    Expert Comment

    Did you use your node or your cluster name as $server ?

    Author Comment

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

    LVL 26

    Expert Comment

    Do you use space between "mscluster" and ":Win32_TCPIPPrinterPort"? There's no space!
    You can also try with
    $printer = new-object "\\$server\ROOT\mscluster:Win32_Printer"

    Author Comment

    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 "\\$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  <<<< "\\nrbnrw90z\ROOT\mscluster:Win32_Printer"

    I've found a answer here :

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


    Expert Comment

    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,

    Accepted Solution


    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Integrate social media with email signatures

    Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

    In this previous article (, we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
    Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
    This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
    This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now