Bekijk een demo×
×

Zie NinjaOne in actie!

Door dit formulier in te dienen geef ik aan akkoord te gaan met het privacybeleid van NinjaOne.

Hoe PowerShell Gebruiken om Afdrukwachtrijen te Wissen

We vertrouwen allemaal op printers, of het nu op kantoor is of wanneer we op afstand werken. Maar hoe essentieel ze ook zijn, printers kunnen soms kieskeurig zijn. Voor IT-professionals en Managed Service Providers (MSP’s) is het onderhouden van de efficiëntie van printservers van het grootste belang. Dus als er printerproblemen ontstaan, is een effectieve methode om ze op te lossen van onschatbare waarde.

Afdrukwachtrijen begrijpen

Een afdrukwachtrij is een tijdelijke opslagruimte voor afdruktaken die wachten om afgedrukt te worden. Wanneer je een document naar een printer stuurt, gaat het niet direct naar de printerhardware. In plaats daarvan vindt het eerst zijn weg naar de afdrukwachtrij. Van daaruit beheert de afdrukwachtrij deze taken efficiënt en stuurt ze naar de printer wanneer ze klaar zijn.

Net als elk systeem kan de wachtrij voor afdrukken echter problemen ondervinden. Misschien loopt een bepaalde opdracht vast, waardoor volgende opdrachten niet verwerkt kunnen worden. Misschien gaat een printer offline, waardoor de wachtrij zich opstapelt. Deze verstoringen kunnen vertragingen en operationele inefficiënties veroorzaken.

Dit is waar het PowerShell-script dat in deze blogpost wordt besproken van onschatbare waarde wordt. Het is ontworpen om alle taken uit de afdrukwachtrij te verwijderen, zodat het afdrukken soepel verloopt. Zorg ervoor dat je beheerdersrechten hebt om dit script te gebruiken.

Het Script

#Requires -Version 5.1

<#
.SYNOPSIS
    Clears Print Queue for all printers
.DESCRIPTION
    Clears Print Queue for all printers.
    This script will stop the printer spooler service, clear all print jobs, and start the printer spooler service.
    If some print jobs are not cleared, then a reboot might be needed before running this script again.
.EXAMPLE
    No parameters needed
.OUTPUTS
    String
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Release Notes:
    Initial Release
    (c) 2023 NinjaOne
    By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
.COMPONENT
    Printer
#>

[CmdletBinding()]
param ()

begin {
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }
}

process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied. Please run with Administrator privileges."
        exit 1
    }
    Write-Host "Stopping print spooler service"
    $StopProcess = Start-Process -FilePath "C:WINDOWSsystem32net.exe" -ArgumentList "stop", "spooler" -Wait -NoNewWindow -PassThru
    # Exit Code 2 usually means the service is already stopped
    if ($StopProcess.ExitCode -eq 0 -or $StopProcess.ExitCode -eq 2) {
        Write-Host "Stopped print spooler service"
        # Sleep just in case the spooler service is taking some time to stop
        Start-Sleep -Seconds 10
        Write-Host "Clearing all print queues"
        Remove-Item -Path "$env:SystemRootSystem32spoolPRINTERS*" -Force -ErrorAction SilentlyContinue
        Write-Host "Cleared all print queues"

        Write-Host "Starting print spooler service"
        $StartProcess = Start-Process -FilePath "C:WINDOWSsystem32net.exe" -ArgumentList "start", "spooler" -Wait -NoNewWindow -PassThru
        if ($StartProcess.ExitCode -eq 0) {
            Write-Host "Started print spooler service"
        }
        else {
            Write-Host "Could not start Print Spooler service. net start spooler returned exit code of $($StartProcess.ExitCode)"
            exit 1
        }
    }
    else {
        Write-Host "Could not stop Print Spooler service. net stop spooler returned exit code of $($StopProcess.ExitCode)"
        exit 1
    }
    exit 0
}

end {}

 

Toegang tot meer dan 300 scripts in de NinjaOne Dojo

Toegang krijgen

Veiligheidsimplicaties van het Script

Hoewel dit PowerShell script een zegen is voor het beheren van afdrukwachtrijen, is het essentieel om bewust te zijn van de gevolgen voor de beveiliging:

  1. Beheerdersprivileges: Het script heeft beheerdersrechten nodig omdat het in contact staat met services op systeemniveau, zoals de print spooler. Als je geen beheerder bent, moet je dit script niet uitvoeren.
  2. Mogelijke kwetsbaarheden: Als het niet goed beveiligd is, kunnen kwaadwillenden het script misbruiken om afdruktaken te verwijderen of zelfs services te verstoren. Zorg er altijd voor dat het script afkomstig is van betrouwbare bronnen en op veilige locaties wordt bewaard.
  3. Overleg: Als je twijfels hebt over de beveiliging van het script, is het altijd verstandig om een IT-beveiligingsprofessional te raadplegen.

Andere snelle tips voor het oplossen van printerproblemen

Problemen met de printer? Naast het gebruik van het PowerShell-script voor het wissen van de afdrukwachtrij, volgen hier enkele algemene stappen voor probleemoplossing:

  1. Vermogenscontrole: Controleer of het netsnoer van de printer is aangesloten en of het apparaat is ingeschakeld.
  2. Connectiviteit: Controleer de aansluiting van de printer op de computer.
  3. Testpagina: Druk een testpagina af om te controleren of de printer goed werkt.
  4. Opnieuw opstarten: Vaak kan een eenvoudige herstart van zowel de computer als de printer veel problemen oplossen.
  5. Ondersteuning door fabrikant: Als de problemen aanhouden, kunt u contact opnemen met de fabrikant van de printer voor speciale ondersteuning.

Slotbeschouwingen:

In het dynamische IT-landschap zijn tools die activiteiten stroomlijnen en echte problemen oplossen van onschatbare waarde. Dit PowerShell-script voor het wissen van afdrukwachtrijen is zo’n hulpmiddel dat zorgt voor efficiënte en soepele afdrukbewerkingen. Benader dergelijke scripts altijd met een goed begrip van het doel, de voordelen en de mogelijke implicaties.

Volgende stappen

Het opbouwen van een efficiënt en effectief IT-team vereist een gecentraliseerde oplossing die fungeert als uw kerndienstleveringstool. NinjaOne stelt IT-teams in staat om al hun apparaten te monitoren, beheren, beveiligen en ondersteunen, waar ze ook zijn, zonder de noodzaak van complexe on-premises infrastructuur.

Leer meer over NinjaOne Endpoint Management, bekijk een live rondleiding, of start uw gratis trial van het NinjaOne-platform

Categorieën:

Dit vindt u misschien ook leuk

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).