You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将创建软件白名单目录的PowerShell手动步骤自动化?

自动化创建白名单软件目录的PowerShell脚本

以下是将手动操作步骤自动化的PowerShell脚本,需以管理员身份运行:

# 1. 设置当前会话的执行策略为Bypass
Set-ExecutionPolicy Bypass -Scope Process -Force

# 2. 定义XML文件路径,请替换<some path>为实际存在的目录路径
$xmlFilePath = "C:\ProgramData\<some path>\CurrentComplete.xml"

# 加载XML并添加指定规则节点
$xmlContent = [xml](Get-Content $xmlFilePath)
$newRule = $xmlContent.CreateElement("Rule")
$newOption = $xmlContent.CreateElement("Option")
$newOption.InnerText = "Enabled:Audit Mode"
$newRule.AppendChild($newOption)
$xmlContent.DocumentElement.AppendChild($newRule)

# 保存修改后的XML文件
$xmlContent.Save($xmlFilePath)

# 3. 将XML文件转换为二进制.bin文件
$binFilePath = Join-Path (Split-Path $xmlFilePath -Parent) "CurrentComplete.bin"
ConvertFrom-CIPolicy -XmlFilePath $xmlFilePath -BinaryFilePath $binFilePath

# 4. 移动生成的.bin文件到系统指定路径(覆盖原有文件)
$targetPolicyPath = "C:\Windows\System32\CodeIntegrity\SiPolicy.p7b"
Move-Item -Path $binFilePath -Destination $targetPolicyPath -Force

# 5. 立即重启计算机
shutdown -r -t 1

关键提示

  • 必须替换脚本中的<some path>为实际的目录路径,否则无法找到目标XML文件
  • 脚本需以管理员权限启动PowerShell执行,否则会因权限不足导致文件修改、移动操作失败
  • 执行策略的修改仅对当前PowerShell会话生效,不会永久更改系统全局执行策略
  • 重启操作会立即执行,请提前保存所有未完成的工作

内容的提问来源于stack exchange,提问作者Santoshkumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 21:52:40