Reputation: 2566
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.
Upvotes: 0
Views: 270
Reputation: 9133
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()
}
Upvotes: 1