Get Network Printers From A Remote Computer

I am using this to attempt to get a list of printers on a remote computer:

Get-WmiObject win32_printer -ComputerName "$oldPcName" 

The problem is I only get local printers, not those printers from the print server connected to the computer. How can I get a list of the network printers?

My goal is to get a list of network printers on a remote computer, remove them, and add different printers from a different print server.

Thanks

3 Answers

#--------------------------
#Set Execution Of PSScripts
#--------------------------
Set-ExecutionPolicy Unrestricted -force
#------------
#Turn Off UAC
#------------
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -PropertyType DWord -Value 0 -Force
#------------------------------
#Enter The Name Of The Computer
#------------------------------
$comp = "Name of computer"
#or if you wish to be prompted for the computer name
$comp = Read-host 'Enter the name of the computer?'
#---------------------------------------
#Starts WinRM Service On Remote Computer
#---------------------------------------
Import-Module Remote_PSRemoting -force
Set-WinRMListener -computername $comp
Restart-WinRM -computername $comp
Set-WinRMStartUp -computername $comp
Start-Sleep -Seconds 60
#----------------------------------------------
#Establish a PSSession With The Remote Computer
#----------------------------------------------
New-PSSession $comp | Enter-PSSession
#All of the replace commands are used to strip the extra characters and just #give a \\server\printer path return
#-----------------------
#Gets A List Of Printers
#-----------------------
$printers1 = Get-childitem -Path HKCU:\printers\connections | select name
$printers2 = $printers1 -replace '.*,,'
$printers3 = $printers2 -replace ',','\'
$printers = $printers3 -replace '}', ''
------------------------------------------------------
#To Replace The Old Print Server Name With The New One
------------------------------------------------------
$newprinters = $printers -replace 'oldserver','\\newserver'
#--------------------
#Gets Default Printer
#--------------------
$default = Get-itemproperty -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows" | select device
$default1 = $default -replace '.*='
$default2 = $default1 -replace '()'
$default3 = $default2 -replace ',winspool'
$defaultprinter = $default3 -replace ',.*'
------------------------------------------------------
#To Replace The Old Print Server Name With The New One
------------------------------------------------------
$newdefaultprinter = $defaultprinter -replace 'oldserver','\\newserver'
#------------------------
#Deletes The Old Printers
#------------------------
Get-WMIObject Win32_Printer | where{$_.Network -eq 'true'} | foreach{$_.delete()}
#----------------------------------------
#Exits PSSession With The Remote Computer
#----------------------------------------
Exit-PSSession
#-----------
#Turn UAC On
#-----------
#Value = 0 through 4 depending on the level of UAC
New-ItemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\policies\system -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 2 -Force
#------------------------------------
#Turn Off Execution Policy Of Scripts
#------------------------------------
Set-ExecutionPolicy undefined -Force
#####This is as far as I could get with it. I always turn off UAC and Enable Scripts in the beginning and turn them back on ant the end. The summary of this script will give you the new network Printer paths and the users default printers. It also deletes the users old network printers. With powershell versions before windows 8 and server 2012, you would have to create a logon script to add the new printers and mark the default printer using WMI commands. Use could also use a csv file with a list of computer names as an input if you wish to run this command on multiple computers. It would look something like...
$csv = Import-csv -Path pathofcsvfile
foreach ($line in $csv) {
#With a bracket at the end to run through each computer in the list...

This is all much easier with newer versions of Windows as they have the Get-printers cmdlet...

Hopefully that can get you started... I would love to see someone finish this script as I have not had the time at work to do so...

3

On Windows 7

To see networked printers, I read the registry

Function InstalledPrinters ($ComputerName) { Invoke-Command -ComputerName $ComputerName -ScriptBlock { $InstalledPrinters = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Connections" $InstalledPrinters | Add-Member -Name 'PrinterName' -MemberType NoteProperty -Value "" Foreach ($InstalledPrinter in $InstalledPrinters) {$InstalledPrinter.PrinterName = $InstalledPrinter.GetValue("Printer").split("\")[3]} Return $InstalledPrinters | sort PrinterName | select PSComputerName, PrinterName } } 

To remove a network printer:

rundll32.exe PRINTUI.DLL PrintUIEntry /gd /c\\$ComputerName /n\\$PrintServer\$PrinterName Gw /q

To install a network printer:

rundll32.exe PRINTUI.DLL PrintUIEntry /ga /c\\$ComputerName /n\\$PrintServer\$PrinterName Gw /q
1

Hmm. There might be a way to do this with a Raspberry Pi. You connect the raspberry pi to the printer and to wifi, you enable port forwarding for ssh or use VNC viewer to access the Raspberry Pi. Using VNC, you can transfer files to the Raspberry Pi over the network. You then get the Raspberry Pi to print out the files you want.

Its not the best straightforward idea, but thats the only way I know of. Raspberry Pi are also very cheap. Latest model only cost £35. If you wanted to do this way, you would need to make a VNC account, then add your Raspberry Pi into your VNC address book. To do this you need to have Raspbian Desktop, and login to your VNC account on the raspberry Pi.

Raspberry Pi Specs: 1GB DDR2 Ram, 1.4GHZ arm processor, GPIO pins

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like