{"id":211142,"date":"2024-03-05T15:24:54","date_gmt":"2024-03-05T15:24:54","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=211142"},"modified":"2024-03-05T15:26:18","modified_gmt":"2024-03-05T15:26:18","slug":"hur-man-inaktiverar-powershell-2-0-skript-guide","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/sv\/script-hub\/hur-man-inaktiverar-powershell-2-0-skript-guide\/","title":{"rendered":"Hur man inaktiverar PowerShell 2.0: Skript-guide"},"content":{"rendered":"<p>Hejsan, teknikproffs! Om du \u00e4r IT-administrat\u00f6r eller arbetar med hanterade IT-tj\u00e4nster (MSP) vet du att det viktigaste \u00e4r att h\u00e5lla din milj\u00f6 s\u00e4ker. Ett omr\u00e5de som ofta beh\u00f6ver granskas \u00e4r konfigurationen av PowerShell p\u00e5 dina Windows-system. S\u00e5 l\u00e5t oss prata om <strong>PowerShell 2.0 och varf\u00f6r du kanske vill inaktivera den<\/strong>. Eller \u00e4nnu b\u00e4ttre, l\u00e5t oss diskutera ett manus som g\u00f6r jobbet \u00e5t dig.<\/p>\n<h2>Varf\u00f6r inaktivera PowerShell 2.0?<\/h2>\n<p>L\u00e5t oss f\u00f6rst f\u00f6rst\u00e5 varf\u00f6r du skulle vilja inaktivera PowerShell 2.0. Denna \u00e4ldre version av PowerShell saknar m\u00e5nga av de s\u00e4kerhetsfunktioner och f\u00f6rb\u00e4ttringar som finns i nyare versioner. Det \u00e4r praktiskt taget en \u00f6ppen inbjudan till illasinnade akt\u00f6rer att utnyttja era system.<\/p>\n<h2>Inaktivera PowerShell 2.0-skriptet<\/h2>\n<p>Nu n\u00e4r vi har fastst\u00e4llt &#8221;varf\u00f6r&#8221;, l\u00e5t oss prata om &#8221;hur&#8221; Skriptet Disable PowerShell 2.0 \u00e4r din enda l\u00f6sning. Skriptet \u00e4r skrivet i PowerShell 5.1 och \u00e4r utformat f\u00f6r att fungera p\u00e5 Windows 10, Windows Server 2016 och senare.<\/p>\n<h3><strong>H\u00e4r \u00e4r vad detta manus erbjuder:<\/strong><\/h3>\n<h4><em>Kontroll av f\u00f6rh\u00f6jda privilegier<\/em><\/h4>\n<p>Skriptet g\u00f6r en f\u00f6rsta kontroll f\u00f6r att se om det k\u00f6rs med administrat\u00f6rsbeh\u00f6righet, och om inte kommer det att meddela dig att k\u00f6ra det som administrat\u00f6r.<\/p>\n<h4><em>Kontroll av operativsystem och version<\/em><\/h4>\n<p>Innan den f\u00f6rs\u00f6ker ta bort PowerShell 2.0 kontrollerar den din PowerShell-version. Du m\u00e5ste k\u00f6ra PowerShell 5.1 eller senare. Det \u00e4r en bra funktion som s\u00e4kerst\u00e4ller att du inte f\u00f6rst\u00f6r din befintliga installation.<\/p>\n<h4><em>Avl\u00e4gsnande<\/em><\/h4>\n<p>Skriptet anv\u00e4nder olika kommandon<em>(Disable-WindowsOptionalFeature och Uninstall-WindowsFeature<\/em>) baserat p\u00e5 ditt operativsystem f\u00f6r att inaktivera PowerShell 2.0. Om PowerShell 2.0 redan \u00e4r inaktiverat f\u00e5r du ett meddelande om detta.<\/p>\n<h2>Manus<\/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>F\u00e5 tillg\u00e5ng till \u00f6ver 300+ skript i NinjaOne Dojo<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/sv\/kostnadsfri-provperiod-formular\">F\u00e5 tillg\u00e5ng till<\/a><\/p>\n<\/div>\n<h2>Hur man anv\u00e4nder skriptet<\/h2>\n<p>Du beh\u00f6ver inte ange n\u00e5gra parametrar. K\u00f6r skriptet med administrat\u00f6rsbeh\u00f6righet. Skriptet guidar dig genom processen och f\u00e5ngar till och med upp fel s\u00e5 att du vet om n\u00e5got g\u00e5r fel.<\/p>\n<h2>F\u00f6rdelar f\u00f6r IT-proffs och IT-partners<\/h2>\n<p>F\u00f6r IT-proffs och IT-partners \u00e4r f\u00f6rdelarna tv\u00e5faldiga:<\/p>\n<ol>\n<li><strong>F\u00f6rb\u00e4ttrad s\u00e4kerhet<\/strong>: Genom att inaktivera PowerShell 2.0 st\u00e4nger du en s\u00e5rbarhet och g\u00f6r d\u00e4rmed ditt n\u00e4tverk s\u00e4krare.<\/li>\n<li><strong>Effektivitet<\/strong>: Ist\u00e4llet f\u00f6r att manuellt navigera till varje server och system f\u00f6r att inaktivera PowerShell 2.0 kan du automatisera denna uppgift med detta skript.<\/li>\n<\/ol>\n<h2>Avslutande tankar<\/h2>\n<p>Att inaktivera PowerShell 2.0 \u00e4r avg\u00f6rande f\u00f6r att f\u00f6rb\u00e4ttra s\u00e4kerheten i din Windows-milj\u00f6. F\u00f6r IT-proffs och IT-partners som letar efter ett effektivt s\u00e4tt att g\u00f6ra detta \u00e4r v\u00e5rt Disable PowerShell 2.0-skript en gudag\u00e5va. Den automatiserar uppgiften och \u00e4r utrustad med kontroller f\u00f6r att s\u00e4kerst\u00e4lla att du g\u00f6r saker r\u00e4tt.<\/p>\n","protected":false},"author":35,"featured_media":142080,"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":[4255],"class_list":["post-211142","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/script_hub\/211142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/comments?post=211142"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/media\/142080"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/media?parent=211142"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/operating_system?post=211142"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/sv\/wp-json\/wp\/v2\/use_cases?post=211142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}