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

Aperta Adatta ai principianti
#13,423 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@CHX606 ci sta già lavorando.

Dal 2/12/2026.

  • #13428 di @CHX606 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
90/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
markdown, powershell
Ambito
documentation

Direzione di ricerca

Aggiorna l’esempio del registro di EnableScriptBlockLogging in reference/7.4 fino a reference/7.7/Microsoft.PowerShell.Core/About/about_Logging_Windows.md. Inizia leggendo la sezione Using the Registry e confrontando le quattro righe collegate. Il completamento richiede che tutti e quattro gli esempi creino il valore con il tipo di registro corretto e che la verifica documentata produca un valore DWORD e registri i blocchi di script ordinari in una nuova sessione PowerShell 7.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
PowerShell
Stelle
2.6k
Fork
1.7k
Merge medio
3h 49m
PR unite (30g)
5

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MicrosoftDocs/PowerShell-Docs

Tutte le issue di MicrosoftDocs/PowerShell-Docs

Issue simili

Altre issue su Documentation

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.