PowerShell Using Arrays to Disable User AD Accounts

I use this PowerShell script to disable all AD user accounts in a list of target OUs. This script will also disable users further down the AD target child OUs.

$ADServer = "Domain-Controller-server"

# Array variable can be a single or multiple variables.
# A CSV file can be used using the Import-CSV cmdlet into $OUList variable

$OUList = @('OU=OUcontainer1,DC=corp,DC=domain,DC=com','OU=OUcontainer2,DC=corp,DC=domain,DC=com')

$OUList | ForEach-Object {Get-ADUser -server $ADServer -Filter * -SearchBase $_ | Disable-ADAccount}

Source: Github/jtbarrera/PowerShell-scripts/disable-ADusersinOUs.ps1

You may also like...