PoshCode Archive  Artifact [a092eb6212]

Artifact a092eb6212ba659ceebb6eed3302125cc54f3a8a927b4d63dc64d44b17ed3d62:

  • File Disable-Local-Users.ps1 — part of check-in [4c5a39a62e] at 2018-06-10 14:06:54 on branch trunk — Disable or Enable local user accounts based on csv or textfile. (user: Michael Wulff size: 1082)

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