以下是一个使用 PowerShell 设置密码策略的脚本:
powershell
# 设置密码长度最小值为 8
$passwordComplexity = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa").PasswordComplexity
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name "PasswordComplexity" -Value 1
$minPwdLen = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa").MinimumPasswordLength
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name "MinimumPasswordLength" -Value 8
# 设置密码最短使用期限为 7 天(以秒为单位)
$minPwdAge = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters").MinimumPasswordAge
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" -Name "MinimumPasswordAge" -Value (7*86400)
# 设置密码最长使用期限为 90 天(以秒为单位)
$maxPwdAge = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters").MaximumPasswordAge
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" -Name "MaximumPasswordAge" -Value (90*86400)
# 设置强制密码历史为记住 5 个密码
$pwdHistoryLength = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters").PasswordHistoryLength
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" -Name "PasswordHistoryLength" -Value 5
请注意,运行此脚本需要以管理员身份运行 PowerShell。此外,不同的 Windows 版本可能会有一些差异,这个脚本在大多数 Windows 系统上应该可以正常工作,但不能保证在所有环境中都完全适用。在实施密码策略之前,建议先进行测试,以确保不会对系统的正常运行产生不良影响。