# encoding: ascii
# api: powershell
# title: Disable Local Users
# description: Disable or Enable local user accounts based on csv or textfile.
# version: 0.1
# type: script
# author: Michael Wulff
# license: CC0
# x-poshcode-id: 6047
# x-archived: 2016-05-17T12:47:43
# x-published: 2016-10-13T13:36:00
#
# Just change the $UsersToDisable parameter to be able to run in on a local machine.
# The script takes usernames from a textfile and disables them with this script togheter with also adding Password Never Expires and Password Cannot Be Changed to the useraccounts.
#
<# Pointers: #>
$EnableUser = 512
$DisableUser = 2
$PasswordNotExpire = 65536
$PasswordCantChange = 64
$UsersToDisable = "C:\scripts\Users_To_Disable.txt"
$users = Get-Content -path $UsersToDisable
$computer = $env:COMPUTERNAME


<# Main Script #>
Foreach($user in $users){
 $user = [ADSI]"WinNT://$computer/$user"
 $user.userflags = $DisableUser+$PasswordNotExpire+$PasswordCantChange
 #$user.Userflags = $EnableUser+$PasswordNotExpire+$PasswordCantChange
 $user.setinfo()
}
