Sometimes, we have a problem with the printer spooler where documents are getting stuck in the printer queue or the printer spooler service is not running. To fix restart print spooler service issues, use a PowerShell script to check if the printer spooler service is running and restart print spooler service.
In the above image, 2 jobs are stuck/paused in the Printer queue and failed to print.
In this blog post, we will discuss how to fix issues related to printer spooler stopping on Windows using PowerShell script.
How to Fix Print Spooler Service Issue
If files are not being sent to the printer or documents are stuck in the Printer queue, a more common reason is Printer spooler service may not be running.
PowerShell Tip: Run the PowerShell terminal or PowerShell ISE as administrator to restart the Spooler service.
Print Spooler is the Windows service name for print spooler. It is default enabled on all Windows operating systems and server OS. The main job of printer spooler service is to load print drivers, print jobs, queue the jobs, and handle the interaction with the printer.
How to Check the Printer Spooler Service Status
To check the printer spooler service status, use the Get-Service cmdlet in PowerShell.
$PrintSpooler = Get-Service -Name Spooler # Get the Print Spooler Service status (Running or Stopped $PrintSpooler
In the above PowerShell script, the Get-Service command gets the spooler service object and assigns it to the $PrintSpooler
variable.
In the next command, it prints the contents of the $PrintSpooler variable. It outputs print spooler service Status, Name, and Display name as below.
How to Restart Print Spooler with PowerShell
To restart the print spooler service with PowerShell, use the Get-Service command to get the spooler server object. The Start-Service command is used to start the print spooler service on the local computer.
$PrintSpooler = Get-Service -Name Spooler # Get the Print Spooler Service status (Running or Stopped) $PrintSpooler # Logic to check Print Spooler Service and restart if not running if($PrintSpooler.Status -eq 'stopped') { # Start Print Spooler Service on local computer Start-Service $PrintSpooler } # Check the Print Spool Service status $PrintSpooler
In the above PowerShell script,
- The Get-Service command gets the Spooler service object and stores it in the
$PrintSpooler
variable. - Check Print Spooler Service Status using the
$PrintSpooler.Status
- Check if the print spooler service is in stopped status.
- If the print spooler service is equal to the stopped status, restart the printer spooler. service using
Start-Service Spooler
command.
Cool Tip: How to get permissions on folders and subfolders!
How to Restart Printer Spooler Service on Workstation
To restart the printer spooler service on a workstation with PowerShell, use the Get-Service command to get the printer spooler object. The Restart-Service command is used to restart the spooler service.
# Get Spooler service object $PrintSpooler = Get-Service -Name Spooler #Restart Printer Spooler Service on WorkStation Restart-Service $PrintSpooler
In the above PowerShell script,
- Get Spooler Service object in $PrintSpooler variable
- Using
Restart-Service
restart the print Spooler service on the Workstation.
Cool Tip: Use test-connection to ping a list of computers using PowerShell!
How to Clean Print Spooler Queue
It may happen that even after restarting of printer spooler service, the printer still not responding, or files are not getting sent to the printer.
To fix these issues, we need to take the backup of the printer queue and later clean the printer spooler queue.
PowerShell Tip: How to get printer properties in PowerShell!
How to Take Backup of Printer Spooler Queue Files
To take the backup of the printer spooler queue files before we clean the printer spooler queue, run the following PowerShell script.
# Stop Spooler Service Stop-Service -Name Spooler -Force # To backup the Spooler files Move-Item -Path "$env:SystemRoot\System32\spool\PRINTERS\*.*" -Destination 'C:\Spooler\Backup\' -Force
The Stop-Service command stops the Spooler service without a prompt for confirmation.
The Move-Item command uses the -Path
parameter to move the spool queue file to the destination path as specified as a backup using the -Destination
parameter.
How to Delete Printer Spooler Queue Files
To delete the printer spooler queue files, use the Remove-Item command that uses the -Path parameter to specify the spool queue file path. The Start-Service command starts the spooler service after deleting the spooler queue files.
# To delete the Printer Spooler files Remove-Item -Path "$env:SystemRoot\System32\spool\PRINTERS\*.*" # Start print spooler service Start-Service -Name Spooler
In the above PowerShell script, the Remove-Item cmdlet takes the printer spooler queue path specified with the $env: path environment variable and deletes all the files from the folders.
Cool Tip: How to use tail – to get the last lines of files in PowerShell!
Conclusion
I hope the above article on how to restart the print spooler service with different PowerShell commands fixes the issues related to the Printer spooler service not responding or the printer spooler service is not in running status.
In such cases, you can restart the print spooler service on the local or remote workstation.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.