是否可以使用 powershell 脚本检查本地安全策略?

Is it possible to check local security policies with a powershell script?

我正在为我们公司的学徒做一个任务。在该任务中,学徒需要在任务主管提供的笔记本上配置本地安全策略。所以为了方便地检查它们,我虽然脚本会很好。但是经过将近 14 小时的谷歌搜索,我没有发现任何好的或有用的东西...

我也尝试了一些微软的文档,但是那些对我没有真正的帮助...他们更让我困惑 xD

我还需要说,我是 PS 的新手...所以任何提示或技巧对我都非常有帮助。

感谢您的宝贵时间:)

虽然有些 com 对象允许使用域策略,但对于本地对象,您必须使用 SECEDIT 导出数据,如评论中所述。然后您可以在 Powershell 中导入导出的数据并对其进行处理。 最后,您仍然可以使用 SECEDIT 导入新数据。

这是一个小例子:

# Export Local Policies
secedit /export /cfg c:\temp\secpol.cfg

# Work with Local Policies data
$secpol = (Get-Content C:\temp\secpol.cfg)

$Value = $secpol | where{ $_ -like "MaximumPasswordAge*" }
$Index = [array]::IndexOf($secpol,$Value)

if($Value -ne "MaximumPasswordAge = 90") {
    $secpol.item($Index) = "MaximumPasswordAge = 90"
}

# Create new policies file
$secpol | out-file c:\temp\secpol.cfg -Force


# Import modified Local Policies
secedit /configure /db c:\windows\security\local.sdb /cfg c:\temp\secpol.cfg /areas SECURITYPOLICY

请注意,此方法有几个限制,因为并非所有本地策略都由 SECEDIT 导出。

另一种方法是使用名为 PolicyFileEditor 的模块。您可以在这里找到它:https://www.powershellgallery.com/packages/PolicyFileEditor/2.0.2