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 Tuesday, July 21, 2015 2:36 PM Added more info
July 21st, 2015 1:58pm

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

Other recent topics Other recent topics