How often do you run in to the situation where you look at the Site Permissions page on a SharePoint site and find out that a couple of the users listed there is no longer at the company? I write situation and not problem because from a security point of view it’s not an issue if you have properly removed or deleted the user in your AD. In addition, you will probably also save a couple of Help Desk calls from confused Site Owners that wonders why the former employee is not automatically removed and worries if he or she still has access to the site.

As you might know this is not done automatically and it’s not possible with any standard out-of-the-Box feature in either WSS or Moss but it can be accomplished with PowerShell. The script, which will be described in more detail by Niklas Goude, simply removes the user from the site. This can of course be modified so that i loops through the site collection, but hang on, we will soon update this script with more goodies.

If you are using Moss, you should keep the employees User Profile and My Site, because if you remove the User Profile you will get problems with references pointing to that user e.g. in the Created By field.

What you can do in the My Site to not confuse your users (or if you’re in a larger company where not everyone gets informed when someone quits) is to have a custom Property displaying the employment status.

Now it’s time to check out the script and move over to part 2 at www.powershell.nu. If you want to download it right away you find it on my download section.
This is the second cross-posting together with Niklas Goude, if you missed the first one about how to batch create sites you find the article here.



  1. [...] sites. For instance you could use it in our previous post where we removed old users from a site (found here). So, let’s take a look at the script and get an explanation of how it’s done and what [...]

  2. [...] Mattias Described the Scenario in part 1 of this post [...]

  3. Ankur Sharma on Monday 16, 2009

    I am trying to write a webpart in c# asp.net to delete a sharepint user from a specific group.
    Can you help me in this?

    this is how i am trying to do—-

    SPSecurity.RunWithElevatedPrivileges(delegate
    {
    using (SPWeb oWeb = SPControl.GetContextWeb(HttpContext.Current))
    {
    try
    {
    oWeb.AllowUnsafeUpdates = true;

    oWeb.BreakRoleInheritance(true);

    int ID = oWeb.Users[UserName].ID;

    oWeb.Users.RemoveByID(ID);

    oWeb.Update();
    }
    finally
    {
    oWeb.AllowUnsafeUpdates = false;
    }
    }

    });



Subscribe without commenting