{"id":208606,"date":"2024-01-17T13:17:10","date_gmt":"2024-01-17T13:17:10","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/powershell-borrar-cola-de-impresion\/"},"modified":"2024-03-04T17:10:40","modified_gmt":"2024-03-04T17:10:40","slug":"powershell-borrar-cola-de-impresion","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/es\/script-hub\/powershell-borrar-cola-de-impresion\/","title":{"rendered":"C\u00f3mo utilizar PowerShell para borrar un cola de impresi\u00f3n"},"content":{"rendered":"<p>Todos necesitamos usar la impresora en alg\u00fan momento, ya sea en la oficina o cuando trabajamos desde casa. Pero, por esenciales que sean, las impresoras a veces pueden ser quisquillosas. Para los profesionales de TI y los <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">proveedores de servicios gestionados (MSP)<\/a>, mantener la eficiencia de los servidores de impresi\u00f3n es primordial. Por eso, cuando surgen problemas con las impresoras, disponer de un m\u00e9todo eficaz para resolverlos tiene un valor incalculable.<\/p>\n<h2>Comprender las colas de impresi\u00f3n<\/h2>\n<p>Una cola de impresi\u00f3n es un \u00e1rea de almacenamiento temporal para trabajos de impresi\u00f3n que est\u00e1n a la espera de ser impresos. Cuando env\u00edas un documento a una impresora, no va directamente al hardware de la impresora, sino que primero se dirige a la cola de impresi\u00f3n. A partir de ah\u00ed, la cola de impresi\u00f3n gestiona eficazmente estos trabajos, envi\u00e1ndolos a la impresora cuando est\u00e1n listos.<\/p>\n<p>Sin embargo, como cualquier sistema, la cola de impresi\u00f3n puede tener problemas. Es posible que un trabajo en concreto se atasque, impidiendo que se procesen los siguientes. Quiz\u00e1s una impresora se desconecta y la cola se acumula. Estas interrupciones pueden causar retrasos e ineficiencias operativas.<\/p>\n<p>Aqu\u00ed es donde el script de PowerShell que mencion\u00e1bamos anteriormente resulta clave. Este scrip est\u00e1 dise\u00f1ado para borrar todos los trabajos de la cola de impresi\u00f3n, lo que garantiza la fluidez de las operaciones de impresi\u00f3n. Para utilizar este script, aseg\u00farate de tener derechos de administrador.<\/p>\n<h2>El script<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Clears Print Queue for all printers\r\n.DESCRIPTION\r\n    Clears Print Queue for all printers.\r\n    This script will stop the printer spooler service, clear all print jobs, and start the printer spooler service.\r\n    If some print jobs are not cleared, then a reboot might be needed before running this script again.\r\n.EXAMPLE\r\n    No parameters needed\r\n.OUTPUTS\r\n    String\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n    Release Notes:\r\n    Initial Release\r\n    (c) 2023 NinjaOne\r\n    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.\r\n    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. \r\n    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. \r\n    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. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, 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. \r\n    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. \r\n    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. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n.COMPONENT\r\n    Printer\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam ()\r\n\r\nbegin {\r\n    function Test-IsElevated {\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        $p = New-Object System.Security.Principal.WindowsPrincipal($id)\r\n        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)\r\n    }\r\n}\r\n\r\nprocess {\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Error -Message \"Access Denied. Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n    Write-Host \"Stopping print spooler service\"\r\n    $StopProcess = Start-Process -FilePath \"C:WINDOWSsystem32net.exe\" -ArgumentList \"stop\", \"spooler\" -Wait -NoNewWindow -PassThru\r\n    # Exit Code 2 usually means the service is already stopped\r\n    if ($StopProcess.ExitCode -eq 0 -or $StopProcess.ExitCode -eq 2) {\r\n        Write-Host \"Stopped print spooler service\"\r\n        # Sleep just in case the spooler service is taking some time to stop\r\n        Start-Sleep -Seconds 10\r\n        Write-Host \"Clearing all print queues\"\r\n        Remove-Item -Path \"$env:SystemRootSystem32spoolPRINTERS*\" -Force -ErrorAction SilentlyContinue\r\n        Write-Host \"Cleared all print queues\"\r\n\r\n        Write-Host \"Starting print spooler service\"\r\n        $StartProcess = Start-Process -FilePath \"C:WINDOWSsystem32net.exe\" -ArgumentList \"start\", \"spooler\" -Wait -NoNewWindow -PassThru\r\n        if ($StartProcess.ExitCode -eq 0) {\r\n            Write-Host \"Started print spooler service\"\r\n        }\r\n        else {\r\n            Write-Host \"Could not start Print Spooler service. net start spooler returned exit code of $($StartProcess.ExitCode)\"\r\n            exit 1\r\n        }\r\n    }\r\n    else {\r\n        Write-Host \"Could not stop Print Spooler service. net stop spooler returned exit code of $($StopProcess.ExitCode)\"\r\n        exit 1\r\n    }\r\n    exit 0\r\n}\r\n\r\nend {}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Accede a m\u00e1s de 300 scripts en el Dojo de NinjaOne<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/freetrialform\/\">Accede<\/a><\/p>\n<\/div>\n<h2>Implicaciones de seguridad del script<\/h2>\n<p>Aunque este script de PowerShell es una gran ayuda para gestionar las colas de impresi\u00f3n, es importante que seamos conscientes de sus implicaciones para la seguridad:<\/p>\n<ol>\n<li><strong>Privilegios de administrador:<\/strong> el script requiere privilegios de administrador, ya que interact\u00faa con servicios a nivel del sistema, como el spooler de impresi\u00f3n. Si no eres administrador, no deber\u00edas ejecutar este script.<\/li>\n<li><strong>Posibles vulnerabilidades:<\/strong> si no se protege adecuadamente, ciertos agentes malintencionados podr\u00edan explotar el script, eliminando trabajos de impresi\u00f3n o incluso interrumpiendo los servicios. Aseg\u00farate siempre de que el script procede de fuentes fiables y se guarda en lugares seguros.<\/li>\n<li><strong>Consultar:<\/strong> Si tienes alguna duda sobre la seguridad del script, siempre es aconsejable consultar con un profesional en ciberseguridad.<\/li>\n<\/ol>\n<h2>Otros consejos para solucionar problemas con la impresora<\/h2>\n<p>\u00bfProblemas con la impresora? Adem\u00e1s de utilizar el script de PowerShell para borrar la cola de impresi\u00f3n, a continuaci\u00f3n te damos algunos pasos generales para resolver los problemas.<\/p>\n<ol>\n<li><strong>Control de la alimentaci\u00f3n:<\/strong> aseg\u00farate de que el cable de alimentaci\u00f3n de la impresora est\u00e9 enchufado y de que el dispositivo est\u00e9 encendido.<\/li>\n<li><strong>Conectividad:<\/strong> comprueba la conexi\u00f3n de la impresora al ordenador.<\/li>\n<li><strong>P\u00e1gina de prueba:<\/strong> imprime una p\u00e1gina de prueba para ver si la impresora funciona correctamente.<\/li>\n<li><strong>Reinicio:<\/strong> a menudo, un simple reinicio del ordenador y de la impresora puede resolver muchos problemas.<\/li>\n<li><strong>Soporte del fabricante:<\/strong> si el problema persiste, ponte en contacto con el fabricante de la impresora para obtener asistencia especializada.<\/li>\n<\/ol>\n<h2>Reflexiones finales<\/h2>\n<p>En el din\u00e1mico panorama de las TI, las herramientas que agilizan las operaciones y resuelven problemas del mundo real tienen un valor incalculable. Este script de PowerShell para borrar la cola de impresi\u00f3n es una de esas herramientas, que garantiza operaciones de impresi\u00f3n eficientes y sin problemas. Eso s\u00ed, usa estos scripts teniendo bien claro su prop\u00f3sito, sus beneficios y sus implicaciones.<\/p>\n","protected":false},"author":35,"featured_media":206883,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4212],"use_cases":[4265],"class_list":["post-208606","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows","use_cases-configuracion-del-sistema"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/script_hub\/208606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/comments?post=208606"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/media\/206883"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/media?parent=208606"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/operating_system?post=208606"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/use_cases?post=208606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}