Using Powershell, assuming a list of usernames in a text file - one per line:
get-content d:\data\users.txt |get-aduser |set-aduser -enabled $false
dsmod user "CN=John Doe,CN=Users,DC=microsoft,DC=com" -disabled yes
Script
PowerShell
<# Delete Users from specified OU in AD containing EXAMPLE #1: Delete-MultipleADUser -OUName UserOUname -Namelike TestUse* All Users in specified OU will be deleted Example #2: Delete-MultipleADUser -OUName UserOUname -Namelike TestUse* -Disabled All Users in specified OU will be disabled #> function Delete-MultipleADUser{ param( [string]$ouname = "", [string]$ouSub = "", [string]$Namelike = "", [switch]$Disable ) # Get the logged-on user's domain in DN form $mydom = (get-addomain).distinguishedname # Build the full DN of the target OU if ($ouSub -eq $Null) {$oudn = "OU=$ouname,$mydom"} else {$oudn = "OU=$ouSub,OU=$ouname,$mydom"} $Users = Get-ADUser -Filter {(SamAccountName -like $Namelike)} -SearchBase $oudn If ($Disable -eq $true) {$Users | Disable-Adaccount} else {$Users | remove-AdUser} } <# Enable Users from specified OU in AD containing EXAMPLE #1: Enable-MultipleADUser -OUName UserOUname -Namelike TestUse* -enable All Users in specified OU will be enabled #> function Enable-MultipleADUser{ param( [string]$ouname = "", [string]$ouSub = "", [string]$Namelike = "", [switch]$Enable ) # Get the logged-on user's domain in DN form $mydom = (get-addomain).distinguishedname # Build the full DN of the target OU if ($ouSub -eq $Null) {$oudn = "OU=$ouname,$mydom"} else {$oudn = "OU=$ouSub,OU=$ouname,$mydom"} $2bEna = Get-ADUser -Filter {(SamAccountName -like $Namelike)} -SearchBase $oudn | Enable-Adaccount }
No comments:
Write comments