{"id":387232,"date":"2024-12-02T15:41:05","date_gmt":"2024-12-02T15:41:05","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=387232"},"modified":"2024-12-02T15:41:05","modified_gmt":"2024-12-02T15:41:05","slug":"estado-de-restaurar-sistema","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/es\/script-hub\/estado-de-restaurar-sistema\/","title":{"rendered":"C\u00f3mo consultar el estado de Restaurar sistema con PowerShell para profesionales de TI"},"content":{"rendered":"<p><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Get system restore status powershell&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:769,&quot;3&quot;:{&quot;1&quot;:0},&quot;11&quot;:4,&quot;12&quot;:0}\">\u00bfQuieres aprender <strong>a consultar el estado de Restaurar sistema con PowerShell<\/strong>? <\/span> Restaurar sistema es una funci\u00f3n esencial en los sistemas operativos Windows, que proporciona una red de seguridad a los usuarios al permitirles revertir su sistema a un estado anterior en caso de mal funcionamiento o cambios no deseados.<\/p>\n<p>Para los profesionales de TI y los <a href=\"https:\/\/www.ninjaone.com\/es\/que-es-un-msp\" target=\"_blank\" rel=\"noopener\">proveedores de servicios gestionados (MSP)<\/a>, supervisar el estado de restauraci\u00f3n del sistema en varios dispositivos es esencial para mantener el correcto estado y la fiabilidad del sistema. El <a href=\"https:\/\/www.ninjaone.com\/it-hub\/endpoint-management\/what-is-powershell\/\" target=\"_blank\" rel=\"noopener\">script PowerShell<\/a> proporcionado es una potente herramienta dise\u00f1ada para comprobar el estado de restauraci\u00f3n del sistema en un dispositivo y, opcionalmente, registrar el resultado en un campo personalizado.<\/p>\n<h2>Contexto<\/h2>\n<p>En un panorama en el que la estabilidad del sistema es primordial, la restauraci\u00f3n del sistema ofrece un valioso servicio al permitir una r\u00e1pida recuperaci\u00f3n de los fallos del sistema. Para los profesionales de TI, especialmente los que gestionan numerosos dispositivos, asegurarse de que la restauraci\u00f3n del sistema est\u00e1 activada puede <a href=\"https:\/\/www.ninjaone.com\/it-hub\/it-service-management\/what-is-network-downtime\/\" target=\"_blank\" rel=\"noopener\">evitar importantes tiempos de inactividad<\/a> y <a href=\"https:\/\/www.ninjaone.com\/es\/copia-de-seguridad\/file-and-folder-backup\/\" target=\"_blank\" rel=\"noopener\">p\u00e9rdidas de datos<\/a>.<\/p>\n<p>Este script simplifica el proceso de verificaci\u00f3n del estado de restauraci\u00f3n del sistema y se integra perfectamente con NinjaOne, una popular soluci\u00f3n de gesti\u00f3n de TI, para registrar el estado en un campo personalizado si es necesario.<\/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    Checks the status of System Restore on the device.\r\n.DESCRIPTION\r\n    Checks the status of System Restore on the device.\r\n    When a Custom Field is specified the results will be saved to the Custom Field as \"Enabled\" or \"Disabled\".\r\n\r\n.EXAMPLE\r\n    (No Parameters)\r\n    ## EXAMPLE OUTPUT WITHOUT PARAMS ##\r\n    [Info] System Restore is Disabled\r\n\r\nPARAMETER: -CustomFieldName \"SystemRestore\"\r\n    Saves the results to a custom field.\r\n.EXAMPLE\r\n    -CustomFieldName \"SystemRestore\"\r\n    ## EXAMPLE OUTPUT WITH CustomFieldName ##\r\n    [Info] Attempting to set Custom Field 'SystemRestore'.\r\n    [Info] Successfully set Custom Field 'SystemRestore'!\r\n    [Info] System Restore is Enabled\r\n\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n    Release Notes: Renamed Script\r\nBy 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\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter()]\r\n    [String]$CustomFieldName\r\n)\r\n\r\nbegin {\r\n    function Set-NinjaProperty {\r\n        [CmdletBinding()]\r\n        Param(\r\n            [Parameter(Mandatory = $True)]\r\n            [String]$Name,\r\n            [Parameter()]\r\n            [String]$Type,\r\n            [Parameter(Mandatory = $True, ValueFromPipeline = $True)]\r\n            $Value,\r\n            [Parameter()]\r\n            [String]$DocumentName\r\n        )\r\n    \r\n        $Characters = $Value | Measure-Object -Character | Select-Object -ExpandProperty Characters\r\n        if ($Characters -ge 10000) {\r\n            throw [System.ArgumentOutOfRangeException]::New(\"Character limit exceeded, value is greater than 10,000 characters.\")\r\n        }\r\n        \r\n        # If we're requested to set the field value for a Ninja document we'll specify it here.\r\n        $DocumentationParams = @{}\r\n        if ($DocumentName) { $DocumentationParams[\"DocumentName\"] = $DocumentName }\r\n        \r\n        # This is a list of valid fields that can be set. If no type is given, it will be assumed that the input doesn't need to be changed.\r\n        $ValidFields = \"Attachment\", \"Checkbox\", \"Date\", \"Date or Date Time\", \"Decimal\", \"Dropdown\", \"Email\", \"Integer\", \"IP Address\", \"MultiLine\", \"MultiSelect\", \"Phone\", \"Secure\", \"Text\", \"Time\", \"URL\", \"WYSIWYG\"\r\n        if ($Type -and $ValidFields -notcontains $Type) { Write-Warning \"$Type is an invalid type! Please check here for valid types. https:\/\/ninjarmm.zendesk.com\/hc\/en-us\/articles\/16973443979789-Command-Line-Interface-CLI-Supported-Fields-and-Functionality\" }\r\n        \r\n        # The field below requires additional information to be set\r\n        $NeedsOptions = \"Dropdown\"\r\n        if ($DocumentName) {\r\n            if ($NeedsOptions -contains $Type) {\r\n                # We'll redirect the error output to the success stream to make it easier to error out if nothing was found or something else went wrong.\r\n                $NinjaPropertyOptions = Ninja-Property-Docs-Options -AttributeName $Name @DocumentationParams 2&gt;&amp;1\r\n            }\r\n        }\r\n        else {\r\n            if ($NeedsOptions -contains $Type) {\r\n                $NinjaPropertyOptions = Ninja-Property-Options -Name $Name 2&gt;&amp;1\r\n            }\r\n        }\r\n        \r\n        # If an error is received it will have an exception property, the function will exit with that error information.\r\n        if ($NinjaPropertyOptions.Exception) { throw $NinjaPropertyOptions }\r\n        \r\n        # The below types require values not typically given in order to be set. The below code will convert whatever we're given into a format ninjarmm-cli supports.\r\n        switch ($Type) {\r\n            \"Checkbox\" {\r\n                # While it's highly likely we were given a value like \"True\" or a boolean datatype it's better to be safe than sorry.\r\n                $NinjaValue = [System.Convert]::ToBoolean($Value)\r\n            }\r\n            \"Date or Date Time\" {\r\n                # Ninjarmm-cli expects the GUID of the option to be selected. Therefore, the given value will be matched with a GUID.\r\n                $Date = (Get-Date $Value).ToUniversalTime()\r\n                $TimeSpan = New-TimeSpan (Get-Date \"1970-01-01 00:00:00\") $Date\r\n                $NinjaValue = $TimeSpan.TotalSeconds\r\n            }\r\n            \"Dropdown\" {\r\n                # Ninjarmm-cli is expecting the guid of the option we're trying to select. So we'll match up the value we were given with a guid.\r\n                $Options = $NinjaPropertyOptions -replace '=', ',' | ConvertFrom-Csv -Header \"GUID\", \"Name\"\r\n                $Selection = $Options | Where-Object { $_.Name -eq $Value } | Select-Object -ExpandProperty GUID\r\n        \r\n                if (-not $Selection) {\r\n                    throw [System.ArgumentOutOfRangeException]::New(\"Value is not present in dropdown\")\r\n                }\r\n        \r\n                $NinjaValue = $Selection\r\n            }\r\n            default {\r\n                # All the other types shouldn't require additional work on the input.\r\n                $NinjaValue = $Value\r\n            }\r\n        }\r\n        \r\n        # We'll need to set the field differently depending on if its a field in a Ninja Document or not.\r\n        if ($DocumentName) {\r\n            $CustomField = Ninja-Property-Docs-Set -AttributeName $Name -AttributeValue $NinjaValue @DocumentationParams 2&gt;&amp;1\r\n        }\r\n        else {\r\n            $CustomField = Ninja-Property-Set -Name $Name -Value $NinjaValue 2&gt;&amp;1\r\n        }\r\n        \r\n        if ($CustomField.Exception) {\r\n            throw $CustomField\r\n        }\r\n    }\r\n    if ($env:customFieldName -and $env:customFieldName -ne \"null\") {\r\n        $CustomFieldName = $env:customFieldName\r\n    }\r\n}\r\nprocess {\r\n    # If the registry value is 1, System Restore is enabled.\r\n    $RegValue = Get-ItemPropertyValue -Path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore\\\" -Name \"RPSessionInterval\" -ErrorAction SilentlyContinue\r\n\r\n    $SystemRestoreStatus = if ($RegValue -ge 1) {\r\n        # If either of the above conditions are met, System Restore is enabled.\r\n        Write-Output \"Enabled\"\r\n    }\r\n    else {\r\n        Write-Output \"Disabled\"\r\n    }\r\n\r\n    # If a Custom Field Name is provided, set the Custom Field with the System Restore Status.\r\n    if ($CustomFieldName) {\r\n        try {\r\n            Write-Host \"[Info] Attempting to set Custom Field '$CustomFieldName'.\"\r\n            Set-NinjaProperty -Name $CustomFieldName -Value $SystemRestoreStatus\r\n            Write-Host \"[Info] Successfully set Custom Field '$CustomFieldName'!\"\r\n        }\r\n        catch {\r\n            Write-Host \"[Error] Failed to set Custom Field '$CustomFieldName'.\"\r\n        }\r\n    }\r\n    Write-Host \"[Info] System Restore is $SystemRestoreStatus\"\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/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\/es\/prueba-gratuita-formulario\/\">Obt\u00e9n acceso<\/a><\/p>\n<\/div>\n<h2>An\u00e1lisis detallado<\/h2>\n<p>Veamos c\u00f3mo funciona este script PowerShell.<\/p>\n<h3><em>Inicializaci\u00f3n del script<\/em><\/h3>\n<p>El script comienza con algunos metadatos en forma de comentarios, detallando su prop\u00f3sito, ejemplos de uso y sistemas operativos soportados. Es compatible con Windows 10 y Windows Server 2016, lo que indica que est\u00e1 dise\u00f1ado para entornos modernos.<\/p>\n<p>Esta l\u00ednea especifica que el script requiere PowerShell versi\u00f3n 5.1 o superior.<\/p>\n<h3><em>Par\u00e1metros<\/em><\/h3>\n<p>El script define un \u00fanico par\u00e1metro opcional, CustomFieldName, que permite a los usuarios especificar un nombre de campo personalizado donde se guardar\u00e1 el estado.<\/p>\n<h3><em>Funci\u00f3n auxiliar: Set-NinjaProperty<\/em><\/h3>\n<p>El script incluye una funci\u00f3n de ayuda, Set-NinjaProperty, que es responsable de establecer el valor del campo personalizado en NinjaOne. Esta funci\u00f3n maneja varios tipos de datos y valida las entradas seg\u00fan criterios predefinidos.<\/p>\n<h3><em>L\u00f3gica principal<\/em><\/h3>\n<p>A continuaci\u00f3n, el script comprueba el registro para determinar si Restaurar sistema est\u00e1 activado. Lee el valor RPSessionInterval de la clave de registro HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore. Si el valor es mayor o igual a 1, se considera que Restaurar sistema est\u00e1 activado.<\/p>\n<p>Si se proporciona un nombre de campo personalizado, el script intenta establecer este campo con el estado de Restaurar sistema mediante la funci\u00f3n Set-NinjaProperty.<\/p>\n<h2>Posibles casos de uso<\/h2>\n<p>Imagina a un profesional de TI que gestiona una flota de dispositivos Windows para una empresa mediana. Asegurarse de que Restaurar sistema est\u00e1 activado en todos los dispositivos es crucial para recuperarse r\u00e1pidamente de posibles problemas. El profesional puede utilizar este script en combinaci\u00f3n con NinjaOne para comprobar y registrar regularmente el estado de Restaurar sistema en todos los dispositivos, asegur\u00e1ndose de que puede actuar con rapidez si la funci\u00f3n se desactiva en alguna m\u00e1quina.<\/p>\n<h2>Comparaciones<\/h2>\n<p>Existen varios m\u00e9todos para comprobar el estado de Restaurar sistema, como utilizar la interfaz gr\u00e1fica de usuario o diferentes utilidades de l\u00ednea de comandos. Sin embargo, este script PowerShell ofrece un enfoque racionalizado y automatizado que se integra con NinjaOne, proporcionando una soluci\u00f3n escalable para los profesionales de TI que gestionan m\u00faltiples sistemas. A diferencia de las comprobaciones manuales, este script puede programarse y ejecutarse en todos los dispositivos, lo que ahorra tiempo y <a href=\"https:\/\/www.ninjaone.com\/blog\/how-human-error-relates-to-cybersecurity-risks\/\" target=\"_blank\" rel=\"noopener\">reduce los errores humanos<\/a>.<\/p>\n<h2>FAQ<\/h2>\n<h3>P: \u00bfEste script puede activar Restaurar sistema si est\u00e1 desactivado?<\/h3>\n<p>R: No, el script est\u00e1 dise\u00f1ado para comprobar el estado de Restaurar Sistema y registrarlo. Activar Restaurar sistema requerir\u00eda comandos adicionales.<\/p>\n<h3>P: \u00bfEs compatible el script con versiones anteriores de Windows?<\/h3>\n<p>R: El script est\u00e1 dise\u00f1ado para Windows 10 y Windows Server 2016. No se garantiza la compatibilidad con versiones anteriores.<\/p>\n<h3>P: \u00bfQu\u00e9 ocurre si no se indica el nombre del campo personalizado?<\/h3>\n<p>R: Si no se proporciona ning\u00fan nombre de campo personalizado, el script simplemente muestra el estado de Restaurar sistema sin intentar registrarlo.<\/p>\n<h2>Implicaciones<\/h2>\n<p>Conocer el estado de Restaurar sistema en todos los dispositivos gestionados ayuda a los profesionales de TI a garantizar que los sistemas puedan recuperarse en caso de fallos. Este enfoque proactivo puede mejorar significativamente la fiabilidad del sistema y reducir el impacto de posibles problemas.<\/p>\n<h2>Recomendaciones<\/h2>\n<p>Cuando utilices este script, aseg\u00farate de que se ejecuta regularmente para controlar el estado de Restaurar sistema. Int\u00e9gralo en una estrategia m\u00e1s amplia de supervisi\u00f3n y gesti\u00f3n para mantener el sistema en buen estado. Prueba siempre el script en un entorno controlado antes de desplegarlo en varios dispositivos para evitar problemas inesperados.<\/p>\n<h2>Reflexiones finales<\/h2>\n<p>NinjaOne ofrece s\u00f3lidas herramientas para la gesti\u00f3n de TI, y scripts como \u00e9ste mejoran sus capacidades proporcionando soluciones <a href=\"https:\/\/www.ninjaone.com\/es\/rmm\/automatizacion-de-ti\/\" target=\"_blank\" rel=\"noopener\">automatizadas<\/a> y escalables para comprobaciones rutinarias. Asegurarse de que la restauraci\u00f3n del sistema est\u00e1 activada en todos los dispositivos es s\u00f3lo una de las muchas tareas que se pueden agilizar con NinjaOne, ayudando a los profesionales de TI a mantener la integridad del sistema, la fiabilidad y la <a href=\"https:\/\/www.ninjaone.com\/es\/eficiencia\" target=\"_blank\" rel=\"noopener\">eficiencia<\/a>.<\/p>\n","protected":false},"author":35,"featured_media":0,"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":[4262],"class_list":["post-387232","script_hub","type-script_hub","status-publish","hentry","script_hub_category-windows","use_cases-mantenimiento"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/script_hub\/387232","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=387232"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/media?parent=387232"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/operating_system?post=387232"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/es\/wp-json\/wp\/v2\/use_cases?post=387232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}