Trouble getting a list of network printers from a remote computer and installing those printers on a new computer.

답변됨 Trouble getting a list of network printers from a remote computer and installing those printers on a new computer.

  • Thursday, November 15, 2012 3:24 PM
     
      Has Code

    2 weeks into learning powershell, so explain things slowly.

    $oldMachineName would normally be set by the user using Read-host. In the scripts below, I've replaced it with various names to test different scenarios.

    My script:

    $oldPcName = Read-Host "Please enter the name or IP address of the old pc." $oldNetworkPrinters = Get-WmiObject win32_printer -ComputerName "$oldPcName" foreach ($printer in $oldNetworkPrinters) { $fullPath =$printer.name

    write-host $fullPath

    (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection($fullPath)

    }


    The resulting values for $fullPath when I run the script on the old computer, getting its own printer list.

    PDF-XChange 4.0
    Microsoft XPS Document Writer
    Fax
    CutePDF Writer
    \\PPAS0969I\PPAP_RIVERHOUNDS_PCL
    \\PPAS0969I\PPAP_HP5KIT_PCL
    \\PPAS0969I\PPAP_HP5KIT_PS
    \\PPAS0969I\PPAP_RIVERHOUNDS_PS
    \\PPAS0969I\ppap_panthers_pcl

    The resulting values for $fullPath when I run the script on the new computer, getting the old computer's printer list.

    PDF-XChange 4.0
    Microsoft XPS Document Writer
    Fax
    CutePDF Writer

    The resulting values for $fullPath when I run the script on the new computer, getting its own printer list.

    PDF-XChange 4.0
    Microsoft XPS Document Writer
    Fax

    Judging by the presence of CutePDF writer when new computer gets the old list, and the absence of it when new computer gets its own list, I would say the new computer is successfully receiving a list of printers from the old computer. Now, why aren't the network printers included in that list? 


All Replies

  • Thursday, November 15, 2012 4:02 PM
     
      Has Code

    2 weeks into learning powershell, so explain things slowly.

    $oldMachineName would normally be set by the user using Read-host. In the scripts below, I've replaced it with various names to test different scenarios.

    My script:

    $oldPcName = Read-Host "Please enter the name or IP address of the old pc." $oldNetworkPrinters = Get-WmiObject win32_printer -ComputerName "$oldPcName" foreach ($printer in $oldNetworkPrinters) { $fullPath =$printer.name

    write-host $fullPath

    (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection($fullPath)

    }


    The resulting values for $fullPath when I run the script on the old computer, getting its own printer list.

    PDF-XChange 4.0
    Microsoft XPS Document Writer
    Fax
    CutePDF Writer
    \\PPAS0969I\PPAP_RIVERHOUNDS_PCL
    \\PPAS0969I\PPAP_HP5KIT_PCL
    \\PPAS0969I\PPAP_HP5KIT_PS
    \\PPAS0969I\PPAP_RIVERHOUNDS_PS
    \\PPAS0969I\ppap_panthers_pcl

    The resulting values for $fullPath when I run the script on the new computer, getting the old computer's printer list.

    PDF-XChange 4.0
    Microsoft XPS Document Writer
    Fax
    CutePDF Writer

    The resulting values for $fullPath when I run the script on the new computer, getting its own printer list.

    PDF-XChange 4.0
    Microsoft XPS Document Writer
    Fax

    Judging by the presence of CutePDF writer when new computer gets the old list, and the absence of it when new computer gets its own list, I would say the new computer is successfully receiving a list of printers from the old computer. Now, why aren't the network printers included in that list? 


    Why would theny be included.  They are defined on a remote pronter.  They would need to be defined on the local printer for them to list on the local printer.

    Before learning PowerShell or as an important sidelien yuo need to spend some timelearning Windows.  Look up how the WIndows print system works.  Study how printer sharing works and how we attach printers to machines.  There are numerous ways to do this.

    CutePDF is not a printe5r and is not shareable.  It shows as a "pritn service" b3ecuse it is used by the lovcal machine to convert documents.  This is done by renfering a standa5rd inage using teh print subsystem and allowing 'CutePDF' to convert from a single standard format.

    As you leawrn the basics of WIndows technologies these things will become more understandable.  They do pose an issue for someone learning to scritp.  The scripting assumes you are a WIndows technician with fundamental technical knowledge of WIndows.  This may make many examples and excercises very difficult to comprehend.

    I recommend taking a course in Windows technologies.  One of the MSCIT cert courses would be a good place to start.

    Here is a very good overview of the prining architecture in Windows although it may be a bit too technical until you get more of the Windows basics around sharing and the network and WMI.

    http://www.codeproject.com/Articles/8916/Printing-Architecture

    WIthout a solid foundation in how WINdows does common things much of scritp ing can be very difficult to undersztand.  You will eventually figure it out by trial-and-error although this may take a couple of years.  Purposely studying this will only take a month.


    ¯\_(ツ)_/¯

  • Thursday, November 15, 2012 9:30 PM
     
     Answered

    After testing your script it is just as i suspected.

    You only see the printers that are locally defined on the remote computer.  That is because network defined pribters only exist when the user is logged on.

    I tried running yor script both on my local computer and on a remote computer.  On my local computer I got all of the printers defined to me. On the remote computer I got only the ones that are locally defined as in your case ones like CutePDF.

    If i log on to the remote computer and run the script from my local; computer logged in as my self then I see all of the printers defined to me on the remote computer.

    Bottom line is if you wabnt to see the network printers on the remote computer then you have to be logged in as the same account on both computers.

    I hope that helps.

    jrussell97