{"id":255924,"date":"2024-05-17T11:58:02","date_gmt":"2024-05-17T11:58:02","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=255924"},"modified":"2024-05-17T11:58:02","modified_gmt":"2024-05-17T11:58:02","slug":"comprobar-si-existe-ruta-de-acceso","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/es\/script-hub\/comprobar-si-existe-ruta-de-acceso\/","title":{"rendered":"C\u00f3mo comprobar si existe una ruta de acceso utilizando PowerShell"},"content":{"rendered":"<p>En el \u00e1mbito de la administraci\u00f3n de sistemas y la gesti\u00f3n inform\u00e1tica, la automatizaci\u00f3n de las comprobaciones rutinarias es fundamental. Una de estas comprobaciones rutinarias es <strong>verificar la existencia de una ruta de acceso o carpeta espec\u00edfica<\/strong>, una acci\u00f3n que se realiza a menudo para asegurarse de que determinado software o archivos cr\u00edticos est\u00e1n en su sitio. PowerShell ha surgido como un potente lenguaje de scripting que facilita estas tareas, permitiendo a los profesionales de TI agilizar las operaciones con precisi\u00f3n.<\/p>\n<h2>Antecedentes<\/h2>\n<p>El script en cuesti\u00f3n pretende simplificar el proceso de verificaci\u00f3n de rutas, no s\u00f3lo comprobando si existe una ruta de acceso especificada, sino tambi\u00e9n actualizando un campo personalizado en funci\u00f3n de este resultado. Esta doble funcionalidad tiene un valor incalculable para los profesionales de TI y los <a href=\"https:\/\/www.ninjaone.com\/es\/que-es-un-msp\">proveedores de servicios gestionados (MSP)<\/a> que conf\u00edan en los datos en tiempo real para supervisar las instalaciones, las actualizaciones o el estado del software en varios sistemas. Al integrar un mecanismo de retroalimentaci\u00f3n personalizado, el script permite a los usuarios adaptarlo en funci\u00f3n de sus herramientas de supervisi\u00f3n y paneles espec\u00edficos.<\/p>\n<h2>El script para comprobar si existe una ruta de acceso<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">&lt;#\r\n.SYNOPSIS\r\n    Updates a custom field with Yes or No, depending if the path exists or not.\r\n.DESCRIPTION\r\n    Updates a custom field with Yes or No, depending if the path exists or not.\r\n.EXAMPLE\r\n     -Path \"$env:APPDATAZoombin\" -CustomField \"Zoom\"\r\n    Check if Zoom is installed for the current user. Set custom field \"Zoom\" to \"Yes\" if the folder exists or \"No\" if it doesn't.\r\n.EXAMPLE\r\n    PS C:&gt; Set-IfPathExists.ps1 -Path \"$env:APPDATAZoombin\" -CustomField \"Zoom\"\r\n    Check if Zoom is installed for the current user. Set custom field \"Zoom\" to \"Yes\" if the folder exists or \"No\" if it doesn't.\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 7, Windows Server 2008\r\n    Release Notes:\r\n    Initial Release\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#&gt;\r\n[CmdletBinding()]\r\nparam (\r\n    # Path to file or folder\r\n    [Parameter(Mandatory = $true)][String]$Path,\r\n    # THe custom field that we will be updating\r\n    [Parameter(Mandatory = $true)][String]$CustomField,\r\n    # Text that will be saved to the custom field when file\/folder exists\r\n    [Parameter(Mandatory = $false)][String]$Exists = \"Yes\",\r\n    # Text that will be saved to the custom field when file\/folder does not exist\r\n    [Parameter(Mandatory = $false)][String]$NotExist = \"No\"\r\n)\r\n\r\nbegin {}\r\nprocess {\r\n    $CustomFieldValue = $(\r\n        if ($(Test-Path -Path $Path -ErrorAction SilentlyContinue)) {\r\n            $Exists\r\n        }\r\n        else {\r\n            $NotExist\r\n        }\r\n    )\r\n    Ninja-Property-Set -Name $CustomField -Value $CustomFieldValue\r\n}\r\nend {}\r\n<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p style=\"text-align: center;\">Accede a m\u00e1s de 300 scripts en el Dojo de NinjaOne<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.ninjaone.com\/es\/prueba-gratuita-formulario\/\">Obt\u00e9n acceso<\/a><\/p>\n<\/div>\n<h2>An\u00e1lisis detallado<\/h2>\n<p>Desglosemos los componentes del script:<\/p>\n<h3><strong>Par\u00e1metros<\/strong>:<\/h3>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\"><strong>$Path<\/strong>: Especifica la ubicaci\u00f3n del archivo o carpeta.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>$CustomField<\/strong>: Hace referencia al campo personalizado que se actualizar\u00e1 en funci\u00f3n del resultado.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>$Exists<\/strong>: Campo de texto que indica la presencia de una ruta.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\"><strong>$NotExist<\/strong>: Campo de texto que indica la ausencia de ruta.<\/li>\n<\/ul>\n<h3><strong>Bloque de proceso<\/strong>:<\/h3>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\">El cmdlet <strong>Test-Path<\/strong> comprueba si el <strong>$Path<\/strong> especificado existe.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\">En funci\u00f3n del resultado, se asigna a la variable <strong>$CustomFieldValue<\/strong> el valor <strong>$Exists<\/strong> o <strong>$NotExist<\/strong>.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\"><strong>Ninja-Property-Set<\/strong> actualiza el <strong>$CustomField<\/strong> con el <strong>$CustomFieldValue<\/strong>.<\/li>\n<\/ul>\n<h2>Posibles casos de uso<\/h2>\n<p>Pensemos en un responsable de TI que supervisa la implantaci\u00f3n de software en una organizaci\u00f3n. Quiere confirmar que Zoom est\u00e1 instalado en el puesto de trabajo de cada empleado y, en lugar de navegar manualmente por cada uno de ellos, despliega este script en toda la red. Comprueba la existencia de la ruta de instalaci\u00f3n de Zoom y actualiza un panel centralizado que permite al administrador saber, de un vistazo, qu\u00e9 m\u00e1quinas tienen Zoom instalado.<\/p>\n<h2>Comparaciones<\/h2>\n<p>Aunque existen m\u00e9todos manuales para comprobar la existencia de rutas, como navegar por carpetas o emplear la opci\u00f3n de propiedades basada en GUI, <strong>Test-Path<\/strong> de PowerShell es eficiente y escalable. Por otra parte, la integraci\u00f3n de la prueba de trayectoria con un mecanismo de retroalimentaci\u00f3n personalizado, como se ve en este script, ofrece una capa adicional de personalizaci\u00f3n que no suele encontrarse en las soluciones listas para usar.<\/p>\n<h2>FAQ<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\"><strong>\u00bfQu\u00e9 ocurre si el $Path especificado es incorrecto?<\/strong><br \/>\nEl script devolver\u00e1 el valor <strong>$NotExist<\/strong> si no encuentra la ruta.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>\u00bfC\u00f3mo se utiliza Ninja-Property-Set aqu\u00ed?<\/strong><br \/>\nEste es un marcador de posici\u00f3n para una funci\u00f3n hipot\u00e9tica que actualiza las propiedades. En una aplicaci\u00f3n del mundo real, lo sustituir\u00edas por una funci\u00f3n real compatible con tu herramienta de supervisi\u00f3n.<\/li>\n<\/ul>\n<h2>Implicaciones<\/h2>\n<p>Aunque el script ayuda a la automatizaci\u00f3n, tiene cierta repercusi\u00f3n en la seguridad inform\u00e1tica. Si entidades malintencionadas acceden al panel de control, pueden discernir las vulnerabilidades del software bas\u00e1ndose en las instalaciones. Garantizar que los resultados de este script se guardan en un entorno seguro es crucial.<\/p>\n<h2>Recomendaciones<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\">Prueba siempre el script en un entorno controlado antes de desplegarlo.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\">Actualiza peri\u00f3dicamente la lista de rutas que deben comprobarse, asegur\u00e1ndote de que sigue siendo pertinente.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\">Garantiza que los datos generados por el script se almacenan y transmiten de forma segura.<\/li>\n<\/ul>\n<h2>Reflexiones finales<\/h2>\n<p>NinjaOne, como <a href=\"https:\/\/www.ninjaone.com\/es\/\">soluci\u00f3n integrada de gesti\u00f3n de TI<\/a>, puede aprovechar a\u00fan m\u00e1s las capacidades del script. Mediante la integraci\u00f3n de scripts como estos, NinjaOne puede ofrecer una visi\u00f3n m\u00e1s detallada y en tiempo real, permitiendo a los profesionales de TI <a href=\"https:\/\/www.ninjaone.com\/es\/eficiencia\">gestionar y supervisar los sistemas de manera eficiente<\/a>. La combinaci\u00f3n de la versatilidad de PowerShell y la completa plataforma de NinjaOne garantiza unas operaciones de TI s\u00f3lidas y optimizadas.<\/p>\n","protected":false},"author":35,"featured_media":144812,"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":[4259],"class_list":["post-255924","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/script_hub\/255924","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=255924"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/media\/144812"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/media?parent=255924"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/operating_system?post=255924"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/use_cases?post=255924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}