windows 启用密码策略 密码长度最小值为8个字符 密码最短使用期间7天 最长 使用期限 90天 强制密码历史 5个记住的密码 powershell 一键脚本实现

以下是一个使用 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 系统上应该可以正常工作,但不能保证在所有环境中都完全适用。在实施密码策略之前,建议先进行测试,以确保不会对系统的正常运行产生不良影响。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三希

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值