通过secedit工具设置本地安全策略
1 #更改本地策略:设置密码永不过期、禁用密码复杂度 2 $CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand.Path.LastIndexOf('\')+1) 3 If (Test-Path secedit.sdb) {Remove-Item secedit.sdb -Force} 4 $secfile = join-path $CurrentPath "secpol.cfg" 5 #导出当前安全策略模板 6 secedit /export /cfg $secfile /quiet 7 #禁用密码复杂度,设置密码永不过期 8 ((gc $secfile) -replace "PasswordComplexity = 1", "PasswordComplexity = 0" ) -replace "MaximumPasswordAge = 42","MaximumPasswordAge = -1"| Out-File $secfile -force 9 #导入新的安全策略模板(指定要应用到系统的安全性范围为SECURITYPOLICY) 10 secedit /configure /db secedit.sdb /cfg $secfile /areas SECURITYPOLICY /quiet 11 Remove-Item $secfile -Force 12 Remove-Item secedit.sdb -Force