about_Logging_Windows: registry example creates EnableScriptBlockLogging as a string, which PowerShell 7 ignores
Maintainer antworten meist innerhalb von 1 Tag
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
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:
- https://github.com/MicrosoftDocs/PowerShell-Docs/blob/aedd8efe1fece22f04e478c2521c3fccc17ab03d/reference/7.7/Microsoft.PowerShell.Core/About/about_Logging_Windows.md?plain=1#L125-L136
- https://github.com/MicrosoftDocs/PowerShell-Docs/blob/aedd8efe1fece22f04e478c2521c3fccc17ab03d/reference/7.6/Microsoft.PowerShell.Core/About/about_Logging_Windows.md?plain=1#L125-L136
- https://github.com/MicrosoftDocs/PowerShell-Docs/blob/aedd8efe1fece22f04e478c2521c3fccc17ab03d/reference/7.5/Microsoft.PowerShell.Core/About/about_Logging_Windows.md?plain=1#L125-L136
- https://github.com/MicrosoftDocs/PowerShell-Docs/blob/aedd8efe1fece22f04e478c2521c3fccc17ab03d/reference/7.4/Microsoft.PowerShell.Core/About/about_Logging_Windows.md?plain=1#L125-L136
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:
- Only an
int1 or 0 becomes true or false: Utils.cs#L884-L897 - If no value in the key is readable, the policy counts as undefined: Utils.cs#L977-L978
- Undefined means only suspicious script blocks are logged: CompiledScriptBlock.cs#L1429-L1439
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
Content source URL
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
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus MicrosoftDocs/PowerShell-Docs
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
MicrosoftDocs/PowerShell-Docs#13431 ·
Maintainer antworten meist innerhalb von 1 Tag
-
needs-triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100
MicrosoftDocs/PowerShell-Docs#13419 ·
Maintainer antworten meist innerhalb von 1 Tag
-
issue-doc-bug needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
MicrosoftDocs/PowerShell-Docs#13413 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Rename-Item: Tell about NewName parameter allow scriptBlockEvtl. vergeben @gerardrecinto hat das vor 1 Tag übernommen. Offenneeds-triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
MicrosoftDocs/PowerShell-Docs#13412 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
MicrosoftDocs/PowerShell-Docs#13407 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in MicrosoftDocs/PowerShell-Docs
Ähnliche Issues
-
marketing
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
Maintainer antworten meist innerhalb von 1 Tag
-
factory:subtask
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
documentation security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
maiychrus25/OpenTea-DX-OS#221 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
agent-substrate/substrate#4308 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
bug good first issue severity: low
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
TMHSDigital/Spackle#199 ·
Maintainer antworten meist innerhalb von 1 Tag