Powershell script to disable bulk amount of AD accounts

Indie101
Indie101 used Ask the Experts™
on
Script to disable computer accounts in AD

I have a list of computers last logged onto, have this in csv format

What is the best way to disable these machines in bulk, do i need to have the one column samaccount?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Either the SamAccountName or the computer name; doesn't really matter, since a computer's SamAccountName is its name with a trailing '$'.
If you have a column SamAccountName with said property:
Import-Csv -Path C:\Temp\DisableComputer.csv | ForEach-Object {Disable-ADAccount -Identity $_.SamAccountName}

Open in new window

If you have a column Name with just the host name:
Import-Csv -Path C:\Temp\DisableComputer.csv | ForEach-Object {Disable-ADAccount -Identity "$($_.Name)`$"}

Open in new window

Author

Commented:
Thanks will try that out and confirm :)

Author

Commented:
Thats great thanks :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial