Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

get-printer loop failure

$
0
0

Hi All,

Trying to write up a quick script to check if a printer is installed on PC’s within our organization. We don’t have a printer server, and these networked printers are all installed manually on our desktops. They are all Windows 7 Pro, and I’m using Windows 10 Pro. Here’s what I have so far…..

#Printer ports to check computers for $check1 = '10.255.5.27' $check2 = 'IP_10.255.5.27' #List of computers $computers = Get-Content -LiteralPath '\fs01Users$billyhscriptsPowerShellcomputerlist.txt' foreach ($computer in $computers) { write-host "This is testing computer $computer" $ports = (get-printer -ComputerName $computer | select -ExpandProperty portname) if ($ports.Contains($check1) -or ($check2)) { Write-Host $computer + "has this installed" else {write-host "No Printer installed on $computer"} 

}

I’m getting the following error when running for every object on my list.

get-printer : The spooler service is not reachable. Ensure the spooler service is running. At line:12 char:11 + $ports = (get-printer -ComputerName $computer | select -ExpandPropert … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (MSFT_Printer:ROOT/StandardCimv2/MSFT_Printer) [Get-Printer], CimException + FullyQualifiedErrorId : HRESULT 0x800706ba,Get-Printer

The issue appears to be the foreach loop that’s messing up. If i take that away and replace the $computer variable with the actual hostname of the remote PC, I can view all installed printers.

Any idea what I’m doing wrong?

submitted by /u/Julians_Drink
[link] [comments]

The post get-printer loop failure appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles