about_Logging_Windows: registry example creates EnableScriptBlockLogging as a string, which PowerShell 7 ignores
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 90/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- markdown, powershell
调研方向
更新 reference/7.4 到 reference/7.7/Microsoft.PowerShell.Core/About/about_Logging_Windows.md 中的 EnableScriptBlockLogging 注册表示例。首先阅读 Using the Registry 部分,并比较链接的四行。完成意味着四个示例都使用正确的注册表类型创建该值,并且文档中的验证步骤生成一个 DWORD 值,同时在新的 PowerShell 7 会话中记录普通脚本块。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- PowerShell
- 星标
- 2.6k
- 派生
- 1.7k
- 平均合并
- 3 小时 49 分钟
- 30 天内合并 PR
- 5
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MicrosoftDocs/PowerShell-Docs 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 88/100
MicrosoftDocs/PowerShell-Docs#13431 ·
维护者通常 1 天内回复
-
needs-triage
难度 1/5 1 小时以内 新手友好度 68/100
MicrosoftDocs/PowerShell-Docs#13419 ·
维护者通常 1 天内回复
-
issue-doc-bug needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
MicrosoftDocs/PowerShell-Docs#13413 ·
维护者通常 1 天内回复
-
Rename-Item: Tell about NewName parameter allow scriptBlock可能已有人在做 @gerardrecinto 于 1 天前认领。 未关闭needs-triage
难度 1/5 1 小时以内 新手友好度 88/100
MicrosoftDocs/PowerShell-Docs#13412 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
MicrosoftDocs/PowerShell-Docs#13407 ·
维护者通常 1 天内回复
查看 MicrosoftDocs/PowerShell-Docs 的全部 Issue
相似的 Issue
-
enhancement good first issue help wanted
难度 1/5 1-3 小时 新手友好度 92/100
-
area:cli area:docs Platform vdr
难度 2/5 1-3 小时 新手友好度 78/100
NVIDIA-NeMo/Gym#7192 ·
维护者通常 2 天内回复
-
Document lexicon.default.userconfig and lexicon.default.userconfig.enforced in config.sample.php未关闭enhancement feature: settings good first issue
难度 1/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
open-telemetry/semantic-conventions-client-side#72 ·
维护者通常 1 天内回复
-
area: cli area: repo priority: P3 type: chore
难度 2/5 1-3 小时 新手友好度 84/100
appandflow/stim#6826 ·
维护者通常 1 天内回复