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

未关闭 适合新手
#13,423 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@CHX606 已经在做这个了。

开始于 2026年12月2日。

  • #13428 来自 @CHX606 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
90/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
markdown, powershell
领域
documentation

调研方向

更新 reference/7.4 到 reference/7.7/Microsoft.PowerShell.Core/About/about_Logging_Windows.md 中的 EnableScriptBlockLogging 注册表示例。首先阅读 Using the Registry 部分,并比较链接的四行。完成意味着四个示例都使用正确的注册表类型创建该值,并且文档中的验证步骤生成一个 DWORD 值,同时在新的 PowerShell 7 会话中记录普通脚本块。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
PowerShell
星标
2.6k
派生
1.7k
平均合并
3 小时 49 分钟
30 天内合并 PR
5

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MicrosoftDocs/PowerShell-Docs 的其他 Issue

查看 MicrosoftDocs/PowerShell-Docs 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。