I need to look up a list of AD users find the Username of the account, Disable the account and move it to the disabled users list.<\/p>\n
Advertisement
If it doesnt exist I would to know that as well.<\/p>\n
Advertisement
I have a CSV file that has the list of AD user with two columns, First Name, and Last Name.<\/p>\n
Thanks for the help ahead of time. This is what I have so far, but it doesnt pull from a CSV file. I have to find the Account name first and add them to this $users variable.<\/p>\n
$Users = “testuser1”, “testuser2” \nForeach ($User in $Users) { \n$SamAccountName = $User \nif (!(Get-ADUser -Filter { (SamAccountName -eq $SamAccountName) })) { \n#if<\/span> user does not exist, give a warning \nWrite-Warning “User account with username $SamAccountName does NOT exist in Active Directory” \n} \nelseif (Get-ADUser -Filter { (SamAccountName -eq $SamAccountName) -and (Enabled -eq $False) }) { \n#If<\/span> user exists but in disabled state, give a warning \nWrite-Warning “A user account with username $SamAccountName has already been DISABLED in Active Directory.” \n} \nelse { \nGet-ADUser -Identity $SamAccountName | Disable-ADAccount \nWrite-Output “$($SamAccountName) has now been disabled” \n} \n}<\/p>","upvoteCount":9,"answerCount":9,"datePublished":"2024-01-03T18:17:16.000Z","author":{"@type":"Person","name":"marcchevez","url":"https://community.spiceworks.com/u/marcchevez"},"acceptedAnswer":{"@type":"Answer","text":"