简体   繁体   中英

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? Those Windows users are local user accounts (Not AD Accounts). In fact, I found a lot of such scripts for 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()
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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