Get-printer command no longer working

Hey everyone so I have a script running on a 2012 R2 server that queries another print server and gets all the printers statuses. I've been using the get-printer command but it stopped working the other day. 

Here is the error it was giving me:

Get-Printer : The spooler service is not reachable.  Ensure the spooler service is running.


So I've stopped and started the print spooler and restarted both machines with no luck. From what I've read I don't think this command should work going from Windows 8/Server 2012 R2 machine to a Windows 7/Server 2008 R2 machine but it was working for a few weeks then stopped.

Here is the script:

$printers = Get-Printer -ComputerName name | select Name, PrinterStatus

$temp = $printers | Where-Object {$_.Name -match "Carruth 1004 - Single Sided"}
$printers = $printers | Where-Object {$_.Name -notmatch "Microsoft XPS Document Writer" -and $_.Name -notmatch "Single Sided" -and $_.Name -notmatch "Backup"}
$printers += $temp
$printers = $printers | sort name

$ITprinters = $printers | Where-Object {$_.Name -match "IT"}
$ITprinters = $ITprinters |sort name

$ENGprinters = $printers | Where-Object {$_.Name -match "ENG"}
$ENGprinters = $ENGprinters | sort name

$CARprinters = $printers | Where-Object {$_.Name -match "Carruth"}
$CARprinters = $CARprinters | sort name

Function Generate-PrinterXML {
    param (
        [parameter(Mandatory=$true)]
        [PSOBJECT[]]$Printers,
        [parameter(Mandatory=$true)]
        [String]$SaveLocation
    )

    $TempOutputArray = @()
    $TempNameArray = @()

    foreach($printer in $Printers){

        $TempOutputArray += $printer.PrinterStatus

        $trimName = $printer.Name.TrimEnd(" - Double Sided")
        $trimName = $trimName.TrimEnd("- Sing")
        $trimName = $trimName.TrimEnd(" Area")
        $trimName = $trimName.TrimStart("IT ")
        $trimName = $trimName -replace '\D+(\d+)','$1'
        $TempNameArray += $trimName

    }

    $xml=[xml]'<Printers/>'

    for($i=0;$i -lt $TempNameArray.Length;$i++){   
        $n=$xml.DocumentElement.AppendChild($xml.CreateElement('Printer'))
        $n.SetAttribute('id',$TempNameArray[$i])
        $c=$n.AppendChild($xml.CreateElement('Status'))
        $c.InnerText=$TempOutputArray[$i]
    
    }

    $XML.Save($SaveLocation)

}


Generate-PrinterXML -Printers $ITprinters -SaveLocation "C:\inetpub\wwwroot\IT_Hub\Printer_Status\ITPrinters.xml"

Generate-PrinterXML -Printers $ENGprinters -SaveLocation "C:\inetpub\wwwroot\IT_Hub\Printer_Status\ENGPrinters.xml"

Generate-PrinterXML -Printers $CARprinters -SaveLocation "C:\inetpub\wwwroot\IT_Hub\Printer_Status\CARPrinters.xml"


So did something happen to make this stop working or should it have never worked in the first place and why was it working? Thanks for any help I'm a little confused as to why this happened.

EDIT:

Also I should add that this command works but is slower and I would prefer to use the new cmdlet

get-wmiobject -class "Win32_Printer" -namespace "root\CIMV2" -computername name

  • Edited by Cody_Horton 16 hours 34 minutes ago Added more info
July 21st, 2015 10:00am

Firewall?

Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 10:22am

Hey JRV Thanks for the reply. I was really hoping it was that easy but the firewall is already disabled (not my call). Should the get-printer cmdlet work from a Windows 8 machine to a windows 7 machine?
July 21st, 2015 10:33am

Yes but only if you are an admin on the remote system.

Remember that both firewalls need t be opened.

Get-Printer uses WMI so that needs to work correctly.

Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 10:37am

Okay thanks for the reply again I added some info to the original post. I'm an admin on both servers and both firewalls are disabled for the moment. I guess to test the wmi I can run a few command that query it to see if it is working.
July 21st, 2015 10:44am

GWMI Win32_Printer -Computer remotepc

Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 11:02am

Hey JRV that worked fine. That's the commend I was using but get-printer seems to be quicker and I like the output it returns more. So the WMI seems to be working fine any other ideas? Thanks for all the help so far.
July 21st, 2015 11:05am

Restart both machines and try again.

Free Windows Admin Tool Kit Click here and download it now
July 21st, 2015 11:07am

Okay that might have to wait till after hours. I did restart the machine I'm sending the command from this morning and the print server yesterday with no luck but I'll try again if you think it may help. Thanks for the help so far.
July 21st, 2015 11:17am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics