TravFord
TravFord

Reputation: 31

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

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?

Upvotes: 2

Views: 13500

Answers (1)

charleswj81
charleswj81

Reputation: 280

Network printers (those that are shared off another server i.e. PPAS0969I) are per-user so when you query Win32_Printer, you only see the local printers plus those loaded in your current profile.

To help illustrate, try running the following:

gwmi win32_printer | select name,local | ft -a

Upvotes: 2

Related Questions