{"id":208115,"date":"2023-09-25T14:29:54","date_gmt":"2023-09-25T14:29:54","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/come-disabilitare-powershell-2-2\/"},"modified":"2024-03-04T17:49:58","modified_gmt":"2024-03-04T17:49:58","slug":"come-disabilitare-powershell-2-2","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/it\/script-hub\/come-disabilitare-powershell-2-2\/","title":{"rendered":"Come disabilitare PowerShell 2.0: Guida con script"},"content":{"rendered":"<p><span class=\"TextRun SCXW87359726 BCX0\" lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW87359726 BCX0\">Ciao, professionista della tecnologia! Se <\/span><span class=\"NormalTextRun SCXW87359726 BCX0\">sei<\/span><span class=\"NormalTextRun SCXW87359726 BCX0\"> un amministratore IT o lavori nell&#8217;ambito dei servizi gestiti (MSP), sai gi\u00e0 che mantenere l&#8217;ambiente sicuro \u00e8 una priorit\u00e0 assoluta. Un&#8217;area che spesso deve essere esaminata \u00e8 la configurazione di PowerShell sui sistemi Windows. Quindi, <\/span><span class=\"NormalTextRun SCXW87359726 BCX0\">iniziamo a<\/span><span class=\"NormalTextRun SCXW87359726 BCX0\"> parlare di <strong>PowerShell 2.0 e del motivo per cui \u00e8 consigliabile disabilitarlo<\/strong>. O, ancora meglio, <\/span><span class=\"NormalTextRun SCXW87359726 BCX0\">iniziamo a<\/span><span class=\"NormalTextRun SCXW87359726 BCX0\"> parlare di uno script che lavora al posto tuo per farlo.<\/span><\/span><span class=\"EOP SCXW87359726 BCX0\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2 aria-level=\"2\">Perch\u00e9 disabilitare PowerShell 2.0?<\/h2>\n<p><span data-contrast=\"none\">In primo luogo, cerchiamo di capire perch\u00e9 dovresti voler disabilitare PowerShell 2.0. Questa versione legacy di PowerShell non dispone di molte delle funzioni di sicurezza e dei miglioramenti disponibili nelle versioni pi\u00f9 recenti. \u00c8 praticamente un invito aperto ai malintenzionati a sfruttare i tuoi sistemi.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2 aria-level=\"2\">Lo script per disabilitare PowerShell 2.0<\/h2>\n<p><span data-contrast=\"none\">Ora che abbiamo stabilito il &#8220;perch\u00e9&#8221;, parliamo del &#8220;come&#8221;. Lo script per disabilitare PowerShell 2.0 \u00e8 una soluzione completa. Scritto in PowerShell 5.1, lo script \u00e8 progettato per funzionare su Windows 10, Windows Server 2016 e versioni successive.<\/span><\/p>\n<h3 aria-level=\"3\"><b><span data-contrast=\"none\">Ecco cosa offre questo script:<\/span><\/b><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<h4 aria-level=\"4\"><i><span data-contrast=\"none\">Controllo dei privilegi elevati<\/span><\/i><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h4>\n<p><span data-contrast=\"none\">Lo script esegue un controllo iniziale per verificare se sia stato eseguito con privilegi amministrativi e, in caso contrario, ti notifica la necessit\u00e0 di essere lanciato da un amministratore.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h4 aria-level=\"4\"><i><span data-contrast=\"none\">Controllo del sistema operativo e della versione<\/span><\/i><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h4>\n<p><span data-contrast=\"none\">Prima di tentare di disabilitare PowerShell 2.0, lo script controlla la versione di PowerShell in uso. \u00c8 necessario eseguire PowerShell 5.1 o successivo. \u00c8 una funzionalit\u00e0 utile, che consente di non creare problemi alla configurazione esistente.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h4 aria-level=\"4\"><i><span data-contrast=\"none\">La rimozione<\/span><\/i><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h4>\n<p><span data-contrast=\"none\">Lo script utilizza diversi comandi (<\/span><i><span data-contrast=\"none\">Disable-WindowsOptionalFeature e Uninstall-WindowsFeature<\/span><\/i><span data-contrast=\"none\">) in base al sistema operativo in uso per disabilitare PowerShell 2.0. Se PowerShell 2.0 \u00e8 gi\u00e0 disabilitato, lo script te lo far\u00e0 sapere.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2>Lo script<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Disables PowerShell 2.0.\r\n.DESCRIPTION\r\n    Disables PowerShell 2.0 by removing the feature.\r\n    This script does require that PowerShell 5.1 be installed before hand.\r\n    See: https:\/\/docs.microsoft.com\/en-us\/powershell\/scripting\/windows-powershell\/wmf\/setup\/install-configure\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#&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\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    if ($PSVersionTable.PSVersion -ge [Version]::new(5, 1)) {\r\n        if ($(Get-Command \"Disable-WindowsOptionalFeature\" -ErrorAction SilentlyContinue).Name -like \"Disable-WindowsOptionalFeature\") {\r\n            if ($(Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2 -ErrorAction SilentlyContinue).State -like \"Enabled\") {\r\n                # Remove PowerShell 2.0 on Windows 10,11\r\n                try {\r\n                    Disable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2 -ErrorAction Stop\r\n                    Write-Host \"Disabled PowerShell 2.0\"\r\n                }\r\n                catch {\r\n                    Write-Error $_\r\n                    Write-Host \"Unable to disable PowerShell 2.0\"\r\n                    exit 1\r\n                }\r\n            }\r\n            if ($(Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root -ErrorAction SilentlyContinue).State -like \"Enabled\") {\r\n                # Remove PowerShell 2.0 on Windows 10, 11, Server 2016\r\n                try {\r\n                    Disable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root -ErrorAction Stop\r\n                    Write-Host \"Disabled PowerShell 2.0\"\r\n                }\r\n                catch {\r\n                    Write-Error $_\r\n                    Write-Host \"Unable to disable PowerShell 2.0\"\r\n                    exit 1\r\n                }\r\n            }\r\n            else {\r\n                Write-Host \"PowerShell is already disabled.\"\r\n            }\r\n        }\r\n        if ($(Get-Command \"Uninstall-WindowsFeature\" -ErrorAction SilentlyContinue).Name -like \"Uninstall-WindowsFeature\") {\r\n            if ($(Get-WindowsFeature -Name PowerShell-V2) -and $(Get-WindowsFeature -Name PowerShell-V2).InstallState -like \"Installed\") {\r\n                # Remove PowerShell 2.0 on Windows Server\r\n                try {\r\n                    Uninstall-WindowsFeature -Name PowerShell-V2 -ErrorAction Stop\r\n                    Write-Host \"Disabled PowerShell 2.0\"\r\n                }\r\n                catch {\r\n                    Write-Error $_\r\n                    Write-Host \"Unable to disable PowerShell 2.0\"\r\n                    exit 1\r\n                }\r\n            }\r\n            else {\r\n                Write-Host \"PowerShell is already disabled.\"\r\n            }\r\n        }\r\n        if (\r\n            $(Get-Command \"Disable-WindowsOptionalFeature\" -ErrorAction SilentlyContinue).Name -notlike \"Disable-WindowsOptionalFeature\" -and \r\n            $(Get-Command \"Uninstall-WindowsFeature\" -ErrorAction SilentlyContinue).Name -notlike \"Uninstall-WindowsFeature\"\r\n        ) {\r\n            Write-Host \"Running on an unsupported version of Windows.\"\r\n            exit 1\r\n        }\r\n    }\r\n    else {\r\n        Write-Host \"Please upgrade to 5.1 before disabling PowerShell 2.0.\"\r\n        exit 1\r\n    }\r\n}\r\nend {}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"blog-cta-new blog-cta-style-1\"><div class=\"cta-left\"><h2><\/h2><p><\/p><\/div><div class=\"cta-right\"><a class=\"button\" href=\"\"><\/a><\/div><\/div>\n<h2 aria-level=\"2\">Come utilizzare lo script<\/h2>\n<p><span data-contrast=\"none\">Non dovrai fornire alcun parametro. Semplicemente, esegui lo script con privilegi amministrativi. Lo script per disabilitare PowerShell 2.0 ti guider\u00e0 attraverso il processo e registrer\u00e0 anche gli errori per avvisarti se qualcosa va storto.<\/span><\/p>\n<h2 aria-level=\"2\">Vantaggi per i professionisti IT e gli MSP<\/h2>\n<p><span data-contrast=\"none\">Per i professionisti IT e gli MSP, i vantaggi sono duplici:<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ol>\n<li><b><span data-contrast=\"none\">Sicurezza migliorata<\/span><\/b><span data-contrast=\"none\">: Disabilitare PowerShell 2.0 significa chiudere un punto di vulnerabilit\u00e0 e rendere cos\u00ec la rete pi\u00f9 sicura.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;201341983&quot;:0,&quot;335559738&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li><b><span data-contrast=\"none\">Efficienza<\/span><\/b><span data-contrast=\"none\">: Invece di navigare manualmente in ogni server e sistema per disabilitare PowerShell 2.0, puoi automatizzare questa attivit\u00e0 con questo script.<\/span><\/li>\n<\/ol>\n<h2>Considerazioni finali<\/h2>\n<p><span class=\"TextRun SCXW133236521 BCX0\" lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW133236521 BCX0\">Disabilitare PowerShell 2.0 \u00e8 fondamentale per migliorare la sicurezza dell&#8217;ambiente Windows. Per i professionisti IT e gli MSP che cercano un modo efficiente per farlo, il nostro script <\/span><span class=\"NormalTextRun SCXW133236521 BCX0\">per disabilitare<\/span><span class=\"NormalTextRun SCXW133236521 BCX0\"> PowerShell 2.0 \u00e8 una manna dal cielo. Automatizza l&#8217;operazione ed \u00e8 dotato di controlli che ti permettono ti essere certo che <\/span><span class=\"NormalTextRun SCXW133236521 BCX0\">tu stia<\/span><span class=\"NormalTextRun SCXW133236521 BCX0\">facendo le cose nel modo giusto.<\/span><\/span><span class=\"EOP SCXW133236521 BCX0\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"author":35,"featured_media":206904,"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":[4275],"class_list":["post-208115","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/script_hub\/208115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/comments?post=208115"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media\/206904"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media?parent=208115"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/operating_system?post=208115"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/use_cases?post=208115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}