如何使用PowerShell命令配置密码策略中的密码最长使用期限?
美国、香港服务器
如何使用PowerShell命令配置密码策略中的密码最长使用期限?
07-11 来源:
一、 PowerShell 执行(独立服务器)
1. 设置密码最长有效期 60 天、最短 1 天、密码长度 14 位、历史密码 24 个
powershell
net accounts /maxpwage:60 /minpwage:1 /minpwlen:14 /uniquepw:24
参数释义:
/maxpwage:60:密码最长使用期限 60 天,到期强制更改;
/minpwage:1:密码修改之后至少 1 天才可以再次修改;
/minpwlen:14:密码最少 14 位;
/uniquepw:24:不能使用前 24 次旧密码。
2. 同时配置账户锁定(5 次输错锁定 30 分钟)
powershell
net accounts /lockoutthreshold:5 /lockoutduration:30 /lockoutwindow:30
3. 查看配置是否生效
powershell
net accounts
输出内容里可以看到:
plaintext
密码最长使用时间(天): 60
密码最短使用时间(天): 1
二、如果你想要修改为 90 天,直接执行下面这条:
powershell
net accounts /maxpwage:90
三、启用密码复杂度(net‑accounts 做不到,必须 secedit)
powershell
secedit /export /cfg C:\secpol.cfg
(Get-Content C:\secpol.cfg) -replace "PasswordComplexity = 0","PasswordComplexity = 1" | Set-Content C:\secpol_new.cfg
secedit /configure /db "$env:windir\security\local.sdb" /cfg C:\secpol_new.cfg /areas SECURITYPOLICY
gpupdate /force
四、域环境(AD 域控服务器才执行下面命令)
powershell
Import-Module ActiveDirectory
Set-ADDefaultDomainPasswordPolicy -Identity yourdomain.com -MaxPasswordAge (New-TimeSpan -Days 60)
五、刷新组策略使配置立即生效
powershell
gpupdate /force
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快