익명 18:15

How to get a list of printers on a remote computer?

How to get a list of printers on 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.



Top Answer/Comment:

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
상단 광고의 [X] 버튼을 누르면 내용이 보입니다