Batch delete Office 365

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Bob Mitchell Bob Mitchell 2 years, 3 months ago.

  • Author
    Posts
  • #18438
    Profile photo of Bob Mitchell
    Bob Mitchell
    Participant

    Hi guys,

    I'm new to PowerShell and Office 365 management, so I hope someone can assist me with what I believe is a rather simple task. I have migrated a couple clients to Office 365 and in both instances, needed to delete multiple users. I ended up using the gui to remove the accounts, but that is an issue if the accounts are not all listed on the same page. You need to select users, delete and then move to the next page. I have the steps I would like to complete listed below.

    1. Export all user to a csv file and include their first name, last name and UPN. (knowing how to do this, I should be able to add other fields as needed in the future)

    2. Using the exported csv file, I will edit it to only include the accounts I want to delete.

    3. Run a PowerShell command that will import the csv and delete the accounts in the file.

    Thanks for any help!

  • #18439
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Office 365 is, for this portion, pretty straightforward.

    You might start at http://blogs.technet.com/b/heyscriptingguy/archive/2014/03/26/se-powershell-to-manage-office-365-users.aspx, which shows how to get lists of O365 users. Those could easily be exported to CSV using Export-CSV. The article includes examples on how to include only licensed users (which is probably what you care about).

    http://technet.microsoft.com/en-us/library/dn194132.aspx details the Remove-MsolUser command, which deletes a user. ObjectId is actually what you probably want, as that parameter accepts pipeline input, meaning you could pipe Import-CSV to it. Looks like UPN would also work.

    Knowing that "MsolUser" is the command name noun portion, you can probably quickly dig up any other commands you may need related to MsolUser management!

    Hope that helps get you started!

  • #18455
    Profile photo of Bob Mitchell
    Bob Mitchell
    Participant

    Thanks for the links. I was able to use that information to get what I needed.

You must be logged in to reply to this topic.