【发布时间】:2017-04-21 21:56:47
【问题描述】:
是否有任何 powershell 脚本可以在 Windows Server 2003 中停用 Windows 用户(来自 CSV 文件)?这些 Windows 用户是本地用户帐户(不是 AD 帐户)。事实上,我发现了很多这样的 AD 脚本。非常感谢您的建议。
【问题讨论】:
标签: windows powershell csv active-directory
是否有任何 powershell 脚本可以在 Windows Server 2003 中停用 Windows 用户(来自 CSV 文件)?这些 Windows 用户是本地用户帐户(不是 AD 帐户)。事实上,我发现了很多这样的 AD 脚本。非常感谢您的建议。
【问题讨论】:
标签: windows powershell csv active-directory
这应该对您有所帮助。请根据您的要求更改占位符:
$EnableUser = 512
$DisableUser = 2
$PasswordNotExpire = 65536 # password never expires
$PasswordCantChange = 64 # passwords cannot be changed
$users = Import-Csv "path\Users_to_disable.csv" # I believe you have only single column else you have to pick the column
$computer = $env:COMPUTERNAME
Foreach($user in $users){ $user = [ADSI]"WinNT://$computer/$user"
$user.userflags = $DisableUser+$PasswordNotExpire+$PasswordCantChange
#$user.Userflags = $EnableUser+$PasswordNotExpire+$PasswordCantChange
$user.setinfo()
}
【讨论】: