Demo ansehen×
×

Sehen Sie NinjaOne in Aktion!

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

Effiziente Überprüfung der Windows-Aktivierung & Lizenzüberprüfung mit PowerShell

Die wichtigsten Erkenntnisse

  • Automatisierte Prüfung der Einhaltung der Vorschriften: Das Skript automatisiert den Prozess der Überprüfung des Windows-Aktivierungs- und Lizenzierungsstatus und stellt die Konformität über mehrere Systeme hinweg sicher.
  • Fehlererkennung und -behebung: Es identifiziert spezifische Windows-Aktivierungsfehler und bietet Schritte zur Fehlerbehebung, die zu einer schnellen Lösung beitragen.
  • Effizienz in der IT-Verwaltung: Automatisiert einen traditionell manuellen Prozess und spart so Zeit und Ressourcen für IT-Experten und MSPs.
  • Unterstützt Rechts- und Sicherheitsstandards: Hilft bei der Einhaltung gesetzlicher Lizenzanforderungen und stellt sicher, dass die Systeme die notwendigen Sicherheitsupdates erhalten.
  • Vielseitig für moderne Windows-Systeme: Entwickelt für Windows 10 und Windows Server 2016 und damit geeignet für moderne IT-Umgebungen.
  • Integration mit IT-Verwaltungstools: Kann in umfassendere IT-Management-Lösungen wie NinjaOne integriert werden, um die Überwachung und Verwaltung zu verbessern.
  • Benutzerfreundliche Ausgabe: Das Skript bietet eine leicht verständliche Ausgabe, so dass es auch für IT-Fachleute mit unterschiedlichem Wissensstand zugänglich ist.

Vorwort

Windows-Aktivierung und -Lizenzierung sind entscheidende Komponenten für die Aufrechterhaltung der Legalität und Funktionalität von Windows-Systemen in der IT-Umgebung. Die Sicherstellung, dass Windows ordnungsgemäß lizenziert und aktiviert ist, ist nicht nur eine rechtliche Anforderung, sondern auch eine Voraussetzung für den Erhalt wichtiger Updates und Support. In diesem Zusammenhang erweisen sich PowerShell-Skripte als leistungsstarke Tools für IT-Experten und Managed Service Provider (MSPs), um den Prozess der Überprüfung des Windows-Aktivierungs- und Lizenzstatus zu automatisieren und zu optimieren.

Hintergrund

Das mitgelieferte PowerShell-Skript dient dazu, den Aktivierungs- und Lizenzstatus von Windows-Betriebssystemen zu ermitteln. Es ist besonders wertvoll in Umgebungen, in denen mehrere Rechner verwaltet werden müssen, um sicherzustellen, dass alle mit den Lizenzanforderungen von Microsoft übereinstimmen. Dieses Skript ist ein Segen für IT-Experten und MSPs, da es ihnen ermöglicht, nicht lizenzierte oder nicht aktivierte Windows-Installationen schnell zu identifizieren und so potenzielle rechtliche Probleme zu vermeiden und die Systemintegrität sicherzustellen.

Das Drehbuch

#Requires -Version 5.1

<#
.SYNOPSIS
    Condition script for detecting activation and license status of Windows.
.DESCRIPTION
    Condition script for detecting activation and license status of Windows.
    Exit codes:
    0 = Activated and Licensed
    2 = Unlicensed, but under a grace period
    3 = Not Activated and Unlicensed
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Release Notes: Renamed script
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 {
    # https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/dn502528(v=ws.11)
    $NotificationReasons = {
        [PSCustomObject]@{
            ErrorCode            = "0xC004C001"
            ErrorMessage         = "The activation server determined the specified product key is invalid"
            ActivationType       = "MAK"
            PossibleCause        = "An invalid MAK was entered."
            TroubleshootingSteps = "Verify that the key is the MAK provided by Microsoft. Contact the Microsoft Activation Call Center to verify that the MAK is valid."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004C003"
            ErrorMessage         = "The activation server determined the specified product key has been blocked"
            ActivationType       = "MAK"
            PossibleCause        = "The MAK is blocked on the activation server."
            TroubleshootingSteps = "Contact the Microsoft Activation Call Center to obtain a new MAK and install/activate the system."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004C008"
            ErrorMessage         = "The activation server reported that the product key has exceeded its unlock limit."
            ActivationType       = "KMS"
            PossibleCause        = "The KMS key has exceeded the activation limit."
            TroubleshootingSteps = "KMS host keys will activate up to 10 times on six different computers. If more activations are necessary, contact the Microsoft Activation Call Center."       
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004C020"
            ErrorMessage         = "The activation server reported that the Multiple Activation Key has exceeded its limit."
            ActivationType       = "MAK"
            PossibleCause        = "The MAK has exceeded the activation limit."
            TroubleshootingSteps = "MAKs by design have a limited number of activations. Contact the Microsoft Activation Call Center."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004C021"
            ErrorMessage         = "The activation server reported that the Multiple Activation Key extension limit has been exceeded."
            ActivationType       = "MAK"
            PossibleCause        = "The MAK has exceeded the activation limit."
            TroubleshootingSteps = "MAKs by design have a limited number of activations. Contact the Microsoft Activation Call Center."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F009"
            ErrorMessage         = "The Software Protection Service reported that the grace period expired."
            ActivationType       = "MAK"
            PossibleCause        = "The grace period expired before the system was activated. Now, the system is in the Notifications state."
            TroubleshootingSteps = "See the section User Experience."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F00F"
            ErrorMessage         = "The Software Licensing Server reported that the hardware ID binding is beyond level the of tolerance."
            ActivationType       = "MAK/KMS client/KMS host"
            PossibleCause        = "The hardware has changed or the drivers were updated on the system."
            TroubleshootingSteps = "MAK: Reactivate the system during the OOT grace period using either online or phone activation. KMS: Restart, or run slmgr.vbs /ato."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F014"
            ErrorMessage         = "The Software Protection Service reported that the product key is not available"
            ActivationType       = "MAK/KMS client"
            PossibleCause        = "No product keys are installed on the system."
            TroubleshootingSteps = "Install a MAK product key, or install a KMS Setup key found in \\sources\\Product.ini on the installation media."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F02C"
            ErrorMessage         = "The Software Protection Service reported that the format for the offline activation data is incorrect."
            ActivationType       = "MAK/KMS client"
            PossibleCause        = "The system has detected that the data entered during phone activation is not valid."
            TroubleshootingSteps = "Verify that the CID is correctly entered."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F038"
            ErrorMessage         = "The Software Protection Service reported that the computer could not be activated. The count reported by your Key Management Service (KMS) is insufficient. Please contact your system administrator."
            ActivationType       = "KMS client"
            PossibleCause        = "The count on the KMS host is not high enough. The KMS count must be ≥5 for Windows Server or ≥25 for Windows client."
            TroubleshootingSteps = "More computers are needed in the KMS pool for KMS clients to activate. Run Slmgr.vbs /dli to get the current count on the KMS host."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F039"
            ErrorMessage         = "The Software Protection Service reported that the computer could not be activated. The Key Management Service (KMS) is not enabled."
            ActivationType       = "KMS client"
            PossibleCause        = "This error occurs when a KMS request is not answered."
            TroubleshootingSteps = "Troubleshoot the network connection between the KMS host and the client. Make sure that TCP port 1688 (default) is not blocked by a firewall or otherwise filtered."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F041"
            ErrorMessage         = "The Software Licensing Service determined that the Key Management Service (KMS) is not activated. KMS needs to be activated. Please contact system administrator."
            ActivationType       = "KMS client"
            PossibleCause        = "The KMS host is not activated."
            TroubleshootingSteps = "Activate the KMS host with either online or phone activation."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F042"
            ErrorMessage         = "The Software Protection Service determined that the specified Key Management Service (KMS) cannot be used."
            ActivationType       = "KMS client"
            PossibleCause        = "Mismatch between the KMS client and the KMS host."
            TroubleshootingSteps = "This error occurs when a KMS client contacts a KMS host that cannot activate the client software. This can be common in mixed environments that contain application and operating system-specific KMS hosts, for example."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F050"
            ErrorMessage         = "The Software Protection Service reported that the product key is invalid."
            ActivationType       = "KMS, KMS client, MAK"
            PossibleCause        = "This can be caused by a typo in the KMS key or by typing in a Beta key on a Released version of the operating system."
            TroubleshootingSteps = "Install the appropriate KMS key on the corresponding version of Windows. Check the spelling. If the key is being copied and pasted, make sure that em dashes have not been substituted for the dashes in the key."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F051"
            ErrorMessage         = "The Software Protection Service reported that the product key is blocked."
            ActivationType       = "MAK/KMS"
            PossibleCause        = "The product key on the activation server is blocked by Microsoft."
            TroubleshootingSteps = "Obtain a new MAK/KMS key, install it on the system, and activate."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F074"
            ErrorMessage         = "The Software Protection Service reported that the computer could not be activated. No Key Management Service (KMS) could be contacted. Please see the Application Event Log for additional information."
            ActivationType       = "KMS Client"
            PossibleCause        = "All KMS host systems  returned an error."
            TroubleshootingSteps = "Troubleshoot errors from each event ID 12288 associated with the activation attempt."
        }
        [PSCustomObject]@{
            ErrorCode            = "0xC004F06C"
            ErrorMessage         = "The Software Protection Service reported that the computer could not be activated. The Key Management Service (KMS) determined that the request timestamp is invalid."
            ActivationType       = "KMS client"
            PossibleCause        = "The system time on the client computer is too different from the time on the KMS host."
            TroubleshootingSteps = "Time sync is important to system and network security for a variety of reasons. Fix this issue by changing the system time on the client to sync with the KMS. Use of a Network Time Protocol (NTP) time source or Active Directory Domain Services for time synchronization is recommended. This issue uses UTP time and is independent of Time Zone selection."
        }
        [PSCustomObject]@{
            ErrorCode            = "0x80070005"
            ErrorMessage         = "Access denied. The requested action requires elevated privileges."
            ActivationType       = "KMS client/MAK/KMS host"
            PossibleCause        = "User Account Control (UAC) prohibits activation processes from running in a non-elevated command prompt."
            TroubleshootingSteps = "Run slmgr.vbs from an elevated command prompt. Right-click cmd.exe, and then click Run as Administrator."
        }
        [PSCustomObject]@{
            ErrorCode            = "0x8007232A"
            ErrorMessage         = "DNS server failure."
            ActivationType       = "KMS host"
            PossibleCause        = "The system has network or DNS issues."
            TroubleshootingSteps = "Troubleshoot network and DNS."
        }
        [PSCustomObject]@{
            ErrorCode            = "0x8007232B"
            ErrorMessage         = "DNS name does not exist."
            ActivationType       = "KMS client"
            PossibleCause        = "The KMS client cannot find KMS SRV RRs in DNS. If a KMS host does not exist on the network, a MAK should be installed."
            TroubleshootingSteps = "Confirm that a KMS host has been installed and DNS publishing is enabled (default). If DNS is unavailable, point the KMS client to the KMS host by using slmgr.vbs /skms \u003ckms_host_name\u003e. Optionally, obtain and install a MAK; then, activate the system. Finally, troubleshoot DNS."
        }
        [PSCustomObject]@{
            ErrorCode            = "0x800706BA"
            ErrorMessage         = "The RPC server is unavailable."
            ActivationType       = "KMS client"
            PossibleCause        = "Firewall settings are not configured on the KMS host, or DNS SRV records are stale."
            TroubleshootingSteps = "Ensure the Key Management Service firewall exception is enabled on the KMS host computer. Ensure that SRV records point to a valid KMS host. Troubleshoot network connections."
        }
        [PSCustomObject]@{
            ErrorCode            = "0x8007251D"
            ErrorMessage         = "No records found for given DNS query."
            ActivationType       = "KMS client"
            PossibleCause        = "The KMS client cannot find KMS SRV RRs in DNS."
            TroubleshootingSteps = "Troubleshoot network connections and DNS."
        }
    }.Invoke()
}
process {
    Write-Host ""

    $LicenseStatus = Get-CimInstance -ClassName "SoftwareLicensingProduct" -Filter "Name like 'Windows%'" -ErrorAction SilentlyContinue |
        Where-Object { $_.PartialProductKey } |
        Select-Object -ExpandProperty LicenseStatus

    $ActivationNumber = switch ($LicenseStatus) {
        0 { 3 }
        1 { 0 }
        2 { 2 }
        3 { 2 }
        4 { 3 }
        5 { 3 }
        6 { 2 }
        default { 3 }
    }

    $Result = cscript.exe C:\Windows\system32\slmgr.vbs -dli
    $Result | Select-Object -Skip 4 | Out-String | Write-Host
    $Notification = $Result -split [System.Environment]::NewLine | Where-Object { $_ -match "^Notification Reason: .*" }
    Write-Host ""
    if ($Notification) {
        $NotificationCode = $($($Notification -split ': ')[1] -split '\.')[0]
        Write-Host "[Error] KMS Activation Error Found."
        if ($NotificationCode -like "0xC004F200") { Write-Host "Non-Genuine" }
        elseif ($NotificationCode -like "0xC004F009") { Write-Host "Grace Time Expired" }
        else {
            $NotificationReasons | Where-Object { $_.ErrorCode -like "$NotificationCode" } | Out-String | Write-Host
        }
    }
    if ($Result -like "*Eval*") {
        Write-Host "Evaluation Licensed"
        exit 5 # Is Activated but is an Evaluation license
    }
    exit $ActivationNumber
}
end {
    
    
    
}

 

Zugriff auf über 300 Skripte im NinjaOne Dojo

Zugang erhalten

Detaillierte Aufschlüsselung

Das Skript beginnt mit der Definition einer Reihe von potenziellen Fehlercodes und Meldungen im Zusammenhang mit der Windows-Aktivierung. Diese sind in einem benutzerdefinierten PowerShell-Objekt gekapselt, das detaillierte Informationen über die Art des Fehlers, die Art der Aktivierung (z. B. MAK, KMS) und Schritte zur Fehlerbehebung enthält.

Im Prozessblock führt das Skript eine Reihe von Befehlen aus:

  • Es ruft den Lizenzstatus von Windows-Produkten mithilfe des Cmdlets Get-CimInstance ab.
  • Der Lizenzstatus wird dann durch eine Switch-Anweisung ausgewertet und in einen Exit-Code übersetzt, der verschiedene Aktivierungs- und Lizenzierungszustände darstellt.
  • Es führt slmgr.vbs -dli aus, ein Skript, das detaillierte Informationen über den Aktivierungs- und Lizenzierungsstatus von Windows liefert.
  • Das Skript analysiert die Ausgabe von slmgr.vbs, um spezifische Aktivierungsfehler zu identifizieren, und liefert die entsprechenden Informationen zur Fehlerbehebung aus den zuvor definierten benutzerdefinierten Objekten.

Mögliche Anwendungsfälle

Stellen Sie sich vor, ein MSP verwaltet die IT-Infrastruktur für ein mittelständisches Unternehmen. Sie können dieses Skript so planen, dass es in regelmäßigen Abständen auf allen Windows-Rechnern ausgeführt wird. Wird ein Rechner mit einer nicht aktivierten oder nicht lizenzierten Windows-Installation gefunden, kann das Skript den MSP alarmieren, so dass dieser umgehend Abhilfemaßnahmen ergreifen kann.

Vergleiche

Herkömmliche Methoden zur Überprüfung der Windows-Aktivierung beinhalten manuelle Überprüfungen auf jedem System oder die Verwendung unterschiedlicher Tools, was zeitaufwändig und inkonsistent sein kann. Dieses Skript bietet einen zentralisierten, automatisierten Ansatz, der Konsistenz gewährleistet und Zeit spart.

FAQs

  • Wie kann ich dieses Skript ausführen?
    • Führen Sie das Skript in PowerShell als Administrator aus.
  • Wird dieses Skript Windows für mich aktivieren?
    • Nein, sie prüft nur den Aktivierungsstatus und bietet Schritte zur Fehlerbehebung.
  • Kann dieses Skript auf allen Windows-Versionen ausgeführt werden?
    • Es ist für Windows 10 und Windows Server 2016 und höher konzipiert.

Auswirkungen

Falsch lizenzierte oder nicht aktivierte Windows-Systeme können ein erhebliches Sicherheitsrisiko darstellen, da sie möglicherweise keine wichtigen Updates erhalten. Dieses Skript hilft bei der Einhaltung von Vorschriften und Sicherheitsstandards innerhalb einer IT-Infrastruktur.

Empfehlungen

  • Planen Sie die Ausführung des Skripts für alle Windows-Rechner in Ihrem Netzwerk regelmäßig.
  • Überprüfen Sie die Ergebnisse des Drehbuchs und handeln Sie umgehend, um die Einhaltung der Vorschriften zu gewährleisten.
  • Stellen Sie sicher, dass die PowerShell-Ausführungsrichtlinien die Ausführung von Skripts zulassen.

Abschließende Überlegungen

Im Bereich der IT-Verwaltung können Tools wie NinjaOne dieses PowerShell-Skript ergänzen, indem sie eine umfassende Plattform für die Überwachung, Verwaltung und Automatisierung von IT-Aufgabenbieten. Die Integration solcher Skripte in eine umfassendere IT-Managementlösung wie NinjaOne kann die Effizienz steigern, die Einhaltung von Vorschriften gewährleisten und die Systemintegrität der gesamten IT-Infrastruktur eines Unternehmens sicherstellen.

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).