{"id":208380,"date":"2024-01-03T11:28:05","date_gmt":"2024-01-03T11:28:05","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/comment-desactiver-powershell-2-0\/"},"modified":"2024-03-04T20:44:49","modified_gmt":"2024-03-04T20:44:49","slug":"comment-desactiver-powershell-2-0","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/comment-desactiver-powershell-2-0\/","title":{"rendered":"Comment d\u00e9sactiver PowerShell 2.0 : Guide avec script"},"content":{"rendered":"<p>Chers professionnels de la technologie, Si vous \u00eates administrateur informatique ou si vous travaillez dans le domaine des services g\u00e9r\u00e9s (MSP), vous savez que la s\u00e9curisation de votre environnement est votre priorit\u00e9. La configuration de PowerShell sur vos syst\u00e8mes Windows est un domaine qui n\u00e9cessite souvent un examen approfondi. Parlons donc de <strong>PowerShell 2.0 et des raisons pour lesquelles vous pourriez vouloir le d\u00e9sactiver<\/strong>. Mieux encore, discutons d&rsquo;un script qui fait le travail \u00e0 votre place.<\/p>\n<h2>Pourquoi d\u00e9sactiver PowerShell 2.0 ?<\/h2>\n<p>Tout d&rsquo;abord, il convient de comprendre pourquoi vous souhaitez d\u00e9sactiver PowerShell 2.0. Cette ancienne version de PowerShell ne dispose pas de la plupart des fonctions de s\u00e9curit\u00e9 et des am\u00e9liorations disponibles dans les versions plus r\u00e9centes. C&rsquo;est pratiquement une invitation ouverte aux acteurs malveillants \u00e0 exploiter vos syst\u00e8mes.<\/p>\n<h2>Le script de d\u00e9sactivation de PowerShell 2.0<\/h2>\n<p>Maintenant que nous avons \u00e9tabli le \u00ab\u00a0pourquoi\u00a0\u00bb, parlons du \u00ab\u00a0comment\u00a0\u00bb. Le script de d\u00e9sactivation de PowerShell 2.0 est votre meilleure solution. \u00c9crit en PowerShell 5.1, le script est con\u00e7u pour fonctionner sur Windows 10, Windows Server 2016 et les versions plus r\u00e9centes.<\/p>\n<h3><strong>Voici ce que permet ce script :<\/strong><\/h3>\n<h4><em>Contr\u00f4le des privil\u00e8ges \u00e9lev\u00e9s<\/em><\/h4>\n<p>Le script effectue une v\u00e9rification initiale pour voir s&rsquo;il est ex\u00e9cut\u00e9 avec des privil\u00e8ges administrateur, et si ce n&rsquo;est pas le cas, il vous demandera de l&rsquo;ex\u00e9cuter en tant qu&rsquo;administrateur.<\/p>\n<h4><em>V\u00e9rification du syst\u00e8me d&rsquo;exploitation et de la version<\/em><\/h4>\n<p>Avant de tenter de supprimer PowerShell 2.0, il v\u00e9rifie votre version de PowerShell. Vous devez utiliser PowerShell 5.1 ou une version plus r\u00e9cente. Il s&rsquo;agit d&rsquo;une fonctionnalit\u00e9 int\u00e9ressante, qui permet de ne pas perturber la configuration existante.<\/p>\n<h4><em>La suppression<\/em><\/h4>\n<p>Le script utilise diff\u00e9rentes commandes (<em>Disable-WindowsOptionalFeature et Uninstall-WindowsFeature<\/em>) en fonction de votre syst\u00e8me d&rsquo;exploitation pour d\u00e9sactiver PowerShell 2.0. Si PowerShell 2.0 est d\u00e9j\u00e0 d\u00e9sactiv\u00e9, il vous le fera savoir.<\/p>\n<h2>Le 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=\"in-context-cta\"><p>Acc\u00e9dez \u00e0 plus de 700 scripts dans le Dojo NinjaOne<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/fr\/phase-de-test-gratuit\/\">Obtenez l&rsquo;acc\u00e8s<\/a><\/p>\n<\/div>\n<h2>Comment utiliser le script<\/h2>\n<p>Vous n&rsquo;avez pas besoin de fournir de param\u00e8tres. Il suffit d&rsquo;ex\u00e9cuter le script avec des privil\u00e8ges administrateur. Le script vous guidera tout au long du processus et d\u00e9tectera m\u00eame les erreurs pour vous avertir en cas de probl\u00e8me.<\/p>\n<h2>Avantages pour les professionnels de l&rsquo;informatique et les entreprises MSP<\/h2>\n<p>Pour les professionnels de l&rsquo;informatique et les MSP, les avantages sont doubles :<\/p>\n<ol>\n<li><strong>S\u00e9curit\u00e9 renforc\u00e9e<\/strong>: En d\u00e9sactivant PowerShell 2.0, vous \u00e9liminez un point de vuln\u00e9rabilit\u00e9 et rendez ainsi votre r\u00e9seau plus s\u00fbr.<\/li>\n<li><strong>Efficacit\u00e9<\/strong>: Au lieu de naviguer manuellement vers chaque serveur et syst\u00e8me pour d\u00e9sactiver PowerShell 2.0, vous pouvez automatiser cette t\u00e2che \u00e0 l&rsquo;aide de ce script.<\/li>\n<\/ol>\n<h2>Conclusions<\/h2>\n<p>La d\u00e9sactivation de PowerShell 2.0 est essentielle pour renforcer la s\u00e9curit\u00e9 de votre environnement Windows. Pour les professionnels de l&rsquo;informatique et les MSP qui recherchent un moyen efficace de le faire, notre script de d\u00e9sactivation de PowerShell 2.0 est une solution id\u00e9ale. Il automatise la t\u00e2che et est \u00e9quip\u00e9 de contr\u00f4les pour s&rsquo;assurer que vous faites les choses correctement.<\/p>\n","protected":false},"author":35,"featured_media":206902,"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":[4287],"class_list":["post-208380","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows","use_cases-configuration-de-systeme"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/208380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/comments?post=208380"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media\/206902"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=208380"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=208380"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=208380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}