如何使用 power shell 脚本设置本地组策略 (gpedit.msc) 的值

How to set value for local group policy(gpedit.msc) using power shell script

我想在本地组策略编辑器中访问此路径 Computer Configuration\Policies\Windows Settings\Security Settings\Account Policies\Password Policy\Maximum password age 并通过 powershell 脚本修改其值。我尝试导入模块组 (Get-Command -Module group*) 但没有 methods/module found.I 在 powershell 中尝试了以下方法但没有成功。

Set-ItemProperty -Path \Computer Configuration\Windows Settings\Security Settings\Account Policies\Password Policy -Name Maximum password age -Value 20

谁能帮我通过 powershell 脚本修改值。

I am new to powershell scripting,so please ignore if any wrong info is provided.

您可以在 windows 注册表中找到它,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters MaximumPasswordAge REG_DWORD

对于像max password age这样的参数,我认为最好的方法是使用net.exe命令。尝试执行

net.exe accounts /? 

对于没有域的计算机中更复杂的组策略,您可以在一台计算机上准备策略,将其导出到文件,然后在其他计算机上导入,使用secedit.exe

尝试google secedit /export, secedit /import 用法

您可以毫无问题地从 powershell 调用 secedit

您可以 get/set 注册表值,使用 [get/set]-itemproperty 命令有点违反直觉。

示例:

Get-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\WinRM\Service\ -Name AllowCredSSP

但是,这可能不会反映在本地组策略编辑器界面中。

查找LGPO.exe,文档很少,但似乎有效: https://blogs.technet.microsoft.com/secguide/2016/01/21/lgpo-exe-local-group-policy-object-utility-v1-0/

(当前下载在"Security Compliance Toolkit") https://www.microsoft.com/en-us/download/details.aspx?id=55319