none
delete bulk users from csv RRS feed

Answers

All replies

  • You don't need a script, you can do it with a single line, something like:

    Import-Csv C:\Users.csv | Foreach-Object {Remove-ADUser -Identity $_.SamAccountName -Confirm:$False }


    http://mariusene.wordpress.com/

    Friday, February 21, 2014 7:33 AM
  • Assuming you have the users samAccountName (logon name) in the CSV file you can use this script to delete accounts

    import-csv c:\Source\deleteusers.csv | foreach {Remove-ADUser -Identity $_.samaccountname -Confirm:$false}

    just change the path to the csv file - the heading in the csv file containing the user logon name should be set to samAccountName


    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    My Blog

    LinkedIn:

    Friday, February 21, 2014 7:41 AM
  • You don't need a script, you can do it with a single line, something like:

    Import-Csv C:\Users.csv | Foreach-Object {Remove-ADUser -Identity $_.SamAccountName -Confirm:$False }


    http://mariusene.wordpress.com/


    sorry - didn't realise you just posted exactly the same thing as me :) - I was in the process of typing when you must have submitted yours

    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    My Blog

    LinkedIn:

    Friday, February 21, 2014 7:42 AM
  • Hi ,

    I tried this but it wont work for me and its says Cannot validate argument on parameter 'identity' and argument is null. so kindly help me on this issue.

    

    Tuesday, March 5, 2019 12:57 PM
  • The script suggested assumes that the CSV file has a header line (the first line) that defines the field "sAMAccountName". The CSV can have other fields, but there must be one user per line, and on each line fields must be comma-delimited.

    Also note that the sAMAccountName is labeled "pre-Windows 2000 logon name" in the "Active Directory Users and Computers" MMC. It may not be the same as the "Name" of the user (the value of the cn attribute of the user object). The "Name" does not uniquely identify the user in AD, while sAMAccountName does.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Tuesday, March 5, 2019 1:30 PM
  • The script suggested assumes that the CSV file has a header line (the first line) that defines the field "sAMAccountName". The CSV can have other fields, but there must be one user per line, and on each line fields must be comma-delimited.

    Also note that the sAMAccountName is labeled "pre-Windows 2000 logon name" in the "Active Directory Users and Computers" MMC. It may not be the same as the "Name" of the user (the value of the cn attribute of the user object). The "Name" does not uniquely identify the user in AD, while sAMAccountName does.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Your comment was also really helpful to get the suggested powershell command working, after I made the CSV following those steps (sAMAccountName as header and each row being comma-delimited).
    Friday, July 10, 2020 5:20 PM