Demo ansehen×
×

Sehen Sie NinjaOne in Aktion!

Mit dem Absenden dieses Formulars akzeptiere ich die Datenschutzerklärung von NinjaOne.

So deaktivieren Sie PowerShell 2.0: Leitfaden mit Skript

Hallo, Technik-Profis! Wenn Sie ein IT-Administrator sind oder im Bereich Managed Services (MSP) arbeiten, wissen Sie, dass die Sicherheit Ihrer Umgebung an erster Stelle steht. Ein Bereich, der häufig überprüft werden muss, ist die Konfiguration von PowerShell auf Ihren Windows-Systemen. Lassen Sie uns also über PowerShell 2.0sprechen und darüber, warum Sie es möglicherweise deaktivieren möchten. Besser noch: Lassen Sie uns über ein Skript sprechen, das diese Aufgabe für Sie übernimmt.

Warum PowerShell 2.0 deaktivieren?

Zunächst einmal sollten Sie verstehen, warum Sie PowerShell 2.0 deaktivieren. In dieser veralteten Version von PowerShell fehlen zahlreiche Sicherheitsfunktionen und Verbesserungen, die in aktuelleren Versionen vorhanden sind. Das ist praktisch eine offene Einladung an böswillige Akteure, Ihre Systeme auszunutzen.

Das PowerShell 2.0-Skript Deaktivieren

Nachdem wir nun das „Warum“ geklärt haben, lassen Sie uns über das „Wie“ sprechen Das Skript zum Deaktivieren von PowerShell 2.0 ist Ihre All-in-One-Lösung. In PowerShell 5.1 verfasst, ist das Skript darauf ausgelegt, auf Windows 10, Windows Server 2016 und neuer zu funktionieren.

Das bietet dieses Skript:

Prüfung auf erhöhte Rechte

Das Skript prüft zunächst, ob es mit Administratorrechten ausgeführt wird, und wenn nicht, werden Sie darauf hingewiesen, dass es als Administrator ausgeführt werden muss.

OS und Versionskontrolle

Bevor es versucht, PowerShell 2.0 zu entfernen, überprüft es Ihre PowerShell-Version. Sie müssen PowerShell 5.1 oder höher ausführen. Das ist eine gute Funktion, die sicherstellt, dass Sie Ihre bestehende Einrichtung nicht durcheinander bringen.

Die Entfernung

Das Skript verwendet verschiedene Befehle(Disable-WindowsOptionalFeature und Uninstall-WindowsFeature) , die auf Ihrem Betriebssystem basieren, um PowerShell 2.0 zu deaktivieren. Wenn PowerShell 2.0 bereits deaktiviert ist, werden Sie darüber informiert.

Das Skript

#Requires -Version 5.1

<#
.SYNOPSIS
    Disables PowerShell 2.0.
.DESCRIPTION
    Disables PowerShell 2.0 by removing the feature.
    This script does require that PowerShell 5.1 be installed before hand.
    See: https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf/setup/install-configure
.EXAMPLE
    No parameters needed.
.OUTPUTS
    String[]
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Release Notes:
    Initial Release
    (c) 2023 NinjaOne
    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.
    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. 
    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. 
    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. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, 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. 
    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. 
    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. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#>

[CmdletBinding()]
param ()

begin {
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }
}
process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied. Please run with Administrator privileges."
        exit 1
    }
    if ($PSVersionTable.PSVersion -ge [Version]::new(5, 1)) {
        if ($(Get-Command "Disable-WindowsOptionalFeature" -ErrorAction SilentlyContinue).Name -like "Disable-WindowsOptionalFeature") {
            if ($(Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2 -ErrorAction SilentlyContinue).State -like "Enabled") {
                # Remove PowerShell 2.0 on Windows 10,11
                try {
                    Disable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2 -ErrorAction Stop
                    Write-Host "Disabled PowerShell 2.0"
                }
                catch {
                    Write-Error $_
                    Write-Host "Unable to disable PowerShell 2.0"
                    exit 1
                }
            }
            if ($(Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root -ErrorAction SilentlyContinue).State -like "Enabled") {
                # Remove PowerShell 2.0 on Windows 10, 11, Server 2016
                try {
                    Disable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root -ErrorAction Stop
                    Write-Host "Disabled PowerShell 2.0"
                }
                catch {
                    Write-Error $_
                    Write-Host "Unable to disable PowerShell 2.0"
                    exit 1
                }
            }
            else {
                Write-Host "PowerShell is already disabled."
            }
        }
        if ($(Get-Command "Uninstall-WindowsFeature" -ErrorAction SilentlyContinue).Name -like "Uninstall-WindowsFeature") {
            if ($(Get-WindowsFeature -Name PowerShell-V2) -and $(Get-WindowsFeature -Name PowerShell-V2).InstallState -like "Installed") {
                # Remove PowerShell 2.0 on Windows Server
                try {
                    Uninstall-WindowsFeature -Name PowerShell-V2 -ErrorAction Stop
                    Write-Host "Disabled PowerShell 2.0"
                }
                catch {
                    Write-Error $_
                    Write-Host "Unable to disable PowerShell 2.0"
                    exit 1
                }
            }
            else {
                Write-Host "PowerShell is already disabled."
            }
        }
        if (
            $(Get-Command "Disable-WindowsOptionalFeature" -ErrorAction SilentlyContinue).Name -notlike "Disable-WindowsOptionalFeature" -and 
            $(Get-Command "Uninstall-WindowsFeature" -ErrorAction SilentlyContinue).Name -notlike "Uninstall-WindowsFeature"
        ) {
            Write-Host "Running on an unsupported version of Windows."
            exit 1
        }
    }
    else {
        Write-Host "Please upgrade to 5.1 before disabling PowerShell 2.0."
        exit 1
    }
}
end {}

 

Zugriff auf über 300 Skripte im NinjaOne Dojo

Zugang erhalten

So verwenden Sie das Skript

Sie brauchen keine Parameter anzugeben. Führen Sie das Skript einfach mit administrativen Rechten aus. Das Skript führt Sie durch den Prozess und fängt sogar Fehler auf, um Sie zu informieren, wenn etwas schief läuft.

Vorteile für IT-Fachleute und MSPs

Für IT-Experten und MSPs ergeben sich daraus zwei Vorteile:

  1. Erhöhte Sicherheit: Durch die Deaktivierung von PowerShell 2.0 schließen Sie eine Schwachstelle und machen so Ihr Netzwerk sicherer.
  2. Effizienz: Anstatt manuell zu jedem Server und System zu navigieren, um PowerShell 2.0 zu deaktivieren, können Sie diese Aufgabe mit diesem Skript automatisieren.

Abschließende Überlegungen

Die Deaktivierung von PowerShell 2.0 ist entscheidend für die Verbesserung der Sicherheit Ihrer Windows-Umgebung. Für IT-Profis und MSPs, die nach einer effizienten Möglichkeit suchen, dies zu tun, ist unser Disable PowerShell 2.0-Skript ein Geschenk des Himmels. Es automatisiert die Aufgabe und ist mit Kontrollen ausgestattet, die sicherstellen, dass Sie alles richtig machen.

Nächste Schritte

Der Aufbau eines effizienten und effektiven IT-Teams erfordert eine zentralisierte Lösung, die als vereintes Tool für die Bereitstellung von Dienstleistungen fungiert. NinjaOne ermöglicht es IT-Teams, all ihre Geräte zu überwachen, verwalten, sichern und zu unterstützen, unabhängig von ihrem Ort und komplexer Infrastruktur vor Ort.

Erfahren Sie mehr über NinjaOne Endpoint Management schauen Sie sich eine Live-Tour an oder starten Sie Ihre kostenlose Testversion der NinjaOne Plattform.

Kategorien:

Das könnte Sie auch interessieren

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • 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.
  • 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.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, 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.
  • 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.
  • 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.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).