about_Logging_Windows: registry example creates EnableScriptBlockLogging as a string, which PowerShell 7 ignores

Offen Anfängerfreundlich
#13,423 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@CHX606 arbeitet bereits daran.

Seit 02.12.2026.

  • #13428 von @CHX606 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
90/100
Issue-Typ
Dokumentation
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
markdown, powershell
Bereich
documentation

Rechercherichtung

Aktualisiere das EnableScriptBlockLogging-Registrierungsbeispiel in reference/7.4 bis reference/7.7/Microsoft.PowerShell.Core/About/about_Logging_Windows.md. Beginne mit dem Lesen des Abschnitts Using the Registry und vergleiche die vier verknüpften Zeilen. Fertig bedeutet, dass alle vier Beispiele den Wert mit dem richtigen Registrierungstyp erstellen und die dokumentierte Überprüfung einen DWORD-Wert erzeugt und gewöhnliche Scriptblöcke in einer neuen PowerShell 7-Sitzung protokolliert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

needs-triage
Type of issue

Code doesn't work

Feedback

The Enable-PSScriptBlockLogging example under "Using the Registry" creates EnableScriptBlockLogging as a REG_SZ "1", because Set-ItemProperty gets the string "1" and no -Type. PowerShell 7 only accepts a REG_DWORD 1 or 0 for this policy and treats any other value as not set. So on a machine with no other policy, running the example doesn't turn on script block logging: PowerShell keeps logging only the script blocks it considers suspicious.

The same line is in all four versions of the article:

Tested on PowerShell 7.7.0, Windows 11 25H2, elevated, with no other script block logging policy set:

Enable-PSScriptBlockLogging   # the function from the article
$key = Get-Item 'HKLM:\Software\Policies\Microsoft\PowerShellCore\ScriptBlockLogging'
$key.GetValueKind('EnableScriptBlockLogging')
# String

In a new pwsh session, Get-Date produces no 4104 event in PowerShellCore/Operational. Only script blocks PowerShell flags as suspicious are logged, as Warning. After changing the value to a DWORD, a new session logs every script block:

Set-ItemProperty $key.PSPath -Name EnableScriptBlockLogging -Value 1 -Type DWord

The policy reader explains why:

Suggested fix, on line 135 in all four versions:

Set-ItemProperty $basePath -Name EnableScriptBlockLogging -Value 1 -Type DWord

Related: SigmaHQ/sigma#6707 detects this value being set to anything other than DWORD 0 or 1.

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_logging_windows?view=powershell-7.6

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.6/Microsoft.PowerShell.Core/About/about_Logging_Windows.md

Author

@sdwheeler

Platform Id

659ef2c1-fa56-c97e-32ba-9460346f13fb

Document Id

8d0f3ca2-b63f-ba18-7f63-0996ce240690

Vorherrschende Sprache
PowerShell
Sterne
2.6k
Forks
1.7k
Ø Merge
3 Std. 49 Min.
Gemergte PRs (30 T.)
5

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus MicrosoftDocs/PowerShell-Docs

Alle Issues in MicrosoftDocs/PowerShell-Docs

Ähnliche Issues

Weitere Issues zu Documentation

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.