简体   繁体   English

Powershell脚本可停用Windows Server 2003中的Windows用户(从CSV文件)

[英]Powershell script to deactivate the Windows users (from CSV file) in Windows Server 2003

Is there any powershell scripts to deactivate the Windows users (from CSV file) in Windows Server 2003? 是否有任何Powershell脚本来停用Windows Server 2003中的Windows用户(从CSV文件)? Those Windows users are local user accounts (Not AD Accounts). 这些Windows用户是本地用户帐户(不是AD帐户)。 In fact, I found a lot of such scripts for AD. 实际上,我发现了很多用于AD的脚本。 Your advice is much appreciated. 非常感谢您的建议。

This should help you. 这应该对您有帮助。 Please change the placeholders according to your requirement: 请根据您的要求更改占位符:

$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()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM