about_Logging_Windows: registry example creates EnableScriptBlockLogging as a string, which PowerShell 7 ignores
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 90/100
- Type d'issue
- Documentation
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- markdown, powershell
- Domaine
- documentation
Piste de recherche
Mettez à jour l’exemple de registre EnableScriptBlockLogging dans reference/7.4 jusqu’à reference/7.7/Microsoft.PowerShell.Core/About/about_Logging_Windows.md. Commencez par lire la section Using the Registry et comparez les quatre lignes liées. L’objectif est que les quatre exemples créent la valeur avec le type de registre correct et que la vérification documentée produise une valeur DWORD et journalise les blocs de script ordinaires dans une nouvelle session PowerShell 7.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- PowerShell
- Étoiles
- 2.6k
- Forks
- 1.7k
- Merge moyen
- 3 h 49 min
- PR mergées (30 j)
- 5
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de MicrosoftDocs/PowerShell-Docs
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
MicrosoftDocs/PowerShell-Docs#13431 ·
Les mainteneurs répondent en général sous 1 jour
-
needs-triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 68/100
MicrosoftDocs/PowerShell-Docs#13419 ·
Les mainteneurs répondent en général sous 1 jour
-
issue-doc-bug needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
MicrosoftDocs/PowerShell-Docs#13413 ·
Les mainteneurs répondent en général sous 1 jour
-
Rename-Item: Tell about NewName parameter allow scriptBlockPeut-être pris @gerardrecinto l’a pris il y a 1 jour. Ouverteneeds-triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
MicrosoftDocs/PowerShell-Docs#13412 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
MicrosoftDocs/PowerShell-Docs#13407 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de MicrosoftDocs/PowerShell-Docs
Issues similaires
-
marketing
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
Les mainteneurs répondent en général sous 1 jour
-
factory:subtask
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
documentation security
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
maiychrus25/OpenTea-DX-OS#221 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
agent-substrate/substrate#4308 ·
Les mainteneurs répondent en général sous 2 jours
-
bug good first issue severity: low
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
TMHSDigital/Spackle#199 ·
Les mainteneurs répondent en général sous 1 jour