Demo ansehen×
×

Sehen Sie NinjaOne in Aktion!

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

Aktivieren von Minidumps unter Windows mit PowerShell

Für die Fehlersuche und -behebung in Computersystemen werden häufig spezielle Tools und Skripte benötigt. Eine solche Methode, die für viele IT-Experten entscheidend ist, ist die Verwendung von Minidump-Dateien. Diese Dateien bieten eine Momentaufnahme des aktiven Speichers, wenn ein Computer abstürzt, und liefern unschätzbare Daten für die Analyse nach dem Absturz. In diesem Artikel wird ein PowerShell-Skript vorgestellt , mit dem die Aktivierung von Minidumps auf Windows-Systemen automatisiert werden kann.

Hintergrund

Für IT-Fachleute und Managed Service Provider (MSPs) ist die Fähigkeit, Daten über Abstürze zu erfassen und zu analysieren, von entscheidender Bedeutung. Auf diese Weise können sie die Gründe für einen Systemabsturz besser nachvollziehen und zukünftige Vorfälle verhindern. Vor allemMinidump-Dateien liefern ausreichend Daten, ohne viel Speicherplatz zu verbrauchen, weshalb sie von vielen Experten bevorzugt werden. Die manuelle Einrichtung der Minidump-Erzeugung kann jedoch mühsam sein, so dass hier eine Automatisierung ins Spiel kommt. Mit Hilfe von Skripten wie dem hier vorgestellten können Fachleute ihre Systeme effizient so einrichten, dass sie bei Bedarf Minidumps erzeugen.

Das Skript

<#
.SYNOPSIS
    Turn on mini dumps if they are off, if other dumps are already enabled do not change the configuration.
.DESCRIPTION
    Turn on mini dumps if they are off, if other dumps are already enabled do not change the configuration.
    This will enable the creation of the pagefile, but set to automatically manage by Windows.
    Reboot might be needed.
.OUTPUTS
    None
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Release Notes:
    Initial Release
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 Set-ItemProp {
        param (
            $Path,
            $Name,
            $Value,
            [ValidateSet("DWord", "QWord", "String", "ExpandedString", "Binary", "MultiString", "Unknown")]
            $PropertyType = "DWord"
        )
        # Do not output errors and continue
        $ErrorActionPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
        if (-not $(Test-Path -Path $Path)) {
            # Check if path does not exist and create the path
            New-Item -Path $Path -Force | Out-Null
        }
        if ((Get-ItemProperty -Path $Path -Name $Name)) {
            # Update property and print out what it was changed from and changed to
            $CurrentValue = Get-ItemProperty -Path $Path -Name $Name
            try {
                Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false -ErrorAction Stop | Out-Null
            }
            catch {
                Write-Error $_
            }
            Write-Host "$Path$Name changed from $CurrentValue to $(Get-ItemProperty -Path $Path -Name $Name)"
        }
        else {
            # Create property with value
            try {
                New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType -Force -Confirm:$false -ErrorAction Stop | Out-Null
            }
            catch {
                Write-Error $_
            }
            Write-Host "Set $Path$Name to $(Get-ItemProperty -Path $Path -Name $Name)"
        }
        $ErrorActionPreference = [System.Management.Automation.ActionPreference]::Continue
    }
    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
    }

    # Reference: https://learn.microsoft.com/en-US/troubleshoot/windows-server/performance/memory-dump-file-options
    $Path = "HKLM:SystemCurrentControlSetControlCrashControl"
    $Name = "CrashDumpEnabled"
    $CurrentValue = Get-ItemPropertyValue -Path $Path -Name $Name -ErrorAction SilentlyContinue
    $Value = 3

    # If CrashDumpEnabled is set to 0 or doesn't exist then enable mini crash dump
    if ($CurrentValue -eq 0 -and $null -ne $CurrentValue) {
        $PageFile = Get-ItemPropertyValue -Path "HKLM:SYSTEMCurrentControlSetControlSession ManagerMemory Management" -Name PagingFiles -ErrorAction SilentlyContinue
        if (-not $PageFile) {
            # If the pagefile was not setup, create the registry entry needed to create the pagefile
            try {
                # Enable automatic page management file if disabled to allow mini dump to function
                Set-ItemProp -Path "HKLM:SYSTEMCurrentControlSetControlSession ManagerMemory Management" -Name PagingFiles -Value "?:pagefile.sys" -PropertyType MultiString
            }
            catch {
                Write-Error "Could not create pagefile."
                exit 1
            }
        }
        Set-ItemProp -Path $Path -Name $Name -Value 3
        Write-Host "Reboot might be needed to enable mini crash dump."
    }
    else {
        Write-Host "Crash dumps are already enabled."
    }
    exit 0
}
end {}

 

Zugriff auf über 300 Skripte im NinjaOne Dojo

Zugang erhalten

Detailansicht

Das vorgestellte PowerShell-Skript beginnt mit der Überprüfung, ob das System über Administratorrechte verfügt. Dies ist wichtig, da Änderungen an der Systemregistrierung, wie sie von diesem Skript beabsichtigt sind, solche Berechtigungen erfordern.

Der wichtigste Registrierungspfad von Interesse ist HKLM:SystemCurrentControlSetControlCrashControl. Innerhalb dieses Pfads gibt es einen speziellen Registrierungsschlüssel, CrashDumpEnabled, der den Status der Crash-Dump-Erzeugung steuert.

Wenn dieser Schlüssel auf 0 gesetzt ist oder nicht existiert, bedeutet dies, dass Crash-Dumps nicht aktiviert sind. Das Skript wird dann Schritte unternehmen, um die Erstellung von Minidumps zu aktivieren. Außerdem prüft das Skript, ob eine Auslagerungsdatei vorhanden ist, und erstellt eine solche, falls sie fehlt, da dies eine Voraussetzung für die Erstellung von Minidumps ist.

Potenzielle Anwendungsfälle

Stellen Sie sich einen IT-Fachmann, Robert, vor, der in einem mittelgroßen Unternehmen arbeitet. Nach mehreren unerklärlichen Systemabstürzen steht Robert unter Druck, die Ursache herauszufinden. Anstatt Maschine für Maschine vorzugehen, setzt Robert dieses Skript auf allen Computern im Unternehmen ein. Dieser proaktive Ansatz stellt sicher, dass Robert beim nächsten Absturz eine Minidump-Datei für die Analyse zur Verfügung hat. Gute Arbeit, Robert!

Alternative Herangehensweise

Um die Minidump-Generierung zu aktivieren, muss man normalerweise durch mehrere Windows-Menüs navigieren oder die Registrierung manuell bearbeiten – beides zeitaufwändige und fehleranfällige Aufgaben. Dieses Skript zeichnet sich dadurch aus, dass es den Prozess automatisiert und so die Gefahr menschlicher Fehler verringert und eine konsistente Einrichtung über mehrere Rechner hinweg gewährleistet.

FAQs

  • Was sind die Voraussetzungen für die Verwendung dieses Skripts?
    Das Skript unterstützt Windows 10 und Windows Server 2016 oder neuere Versionen.
  • Ist nach der Ausführung des Skripts ein Neustart erforderlich?
    Ein Neustart kann erforderlich sein, um die Aktivierung von Mini-Crash-Dumps abzuschließen.
  • Was ist, wenn auf meinem System bereits Crash-Dumps aktiviert sind?
    Das Skript erkennt dies und nimmt keine Änderungen vor.

Auswirkungen

Die Aktivierung der Minidump-Erstellung ist ein zweischneidiges Schwert. Sie bieten zwar wertvolle Daten für die Fehlersuche, können aber auch sensible Informationen enthalten. IT-Experten sollten in Erwägung ziehen, diese Dateien zu verschlüsseln oder sicherzustellen, dass sie an sicheren Orten gespeichert werden.

Empfehlungen

  • Testen Sie das Skript immer in einer kontrollierten Umgebung, bevor Sie es einsetzen.
  • Prüfen und löschen Sie Minidump-Dateien regelmäßig, um Speicherplatz zu sparen und den Datenschutz zu wahren.

Abschließende Überlegungen

Die Einführung automatisierter Lösungen, wie das besprochene Skript, vereinfacht die IT-Verwaltungsaufgaben. Plattformen wie NinjaOne bieten eine zentrale Kontrolle und eine Reihe von Tools, die auf die Bedürfnisse von IT-Fachleuten zugeschnitten sind und sicherstellen, dass die Systeme optimiert und sicher bleiben.

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