SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A user has left the company and I been finding her many different places from main portal to all the site collections, sub sites and SP groups..

Is there a powershell way to delete her from everywhere? (domain\jsmith)

share|improve this question
up vote 2 down vote accepted

Please see the script below, it "Remove / Delete users from all sites and site collections within a web application.":

share|improve this answer
Thanks for the ready-made code... – Rosie O'Donnell Nov 14 '11 at 20:45
No problem, all common tasks are already implemented by someone and blogged:) You just need to know what to solution is right and use it. – Yuri Leontyev Nov 14 '11 at 22:03

To loop through all the sites in a portal use foreach. sample below

$portalUrl = Read-Host "Enter Site URL" 
$rootSite = New-Object Microsoft.SharePoint.SPSite($portalUrl)
$spWebApp = $rootSite.WebApplication 

foreach($site in $spWebApp.Sites)


Implement above foreach code for below if you need to go through each web in a portal.

function RemoveUser([string]$Site, [string]$SiteCollection, [string]$User) {

    # GAC

    [System.Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null

    # Connect To Sharepoint

    $SPSite = New-Object Microsoft.SharePoint.SPSite($Site)
    $OpenWeb = $SPSite.OpenWeb($SiteCollection)

    # Check if User Exists in Site

    if ($OpenWeb.SiteUsers | Where {$_.LoginName -eq $User}) {
        $User = $OpenWeb.SiteUsers | Where {$_.LoginName -eq $User}

        Write-Host "User: $User Successfully Removed from Site: $Site/$SiteCollection"
    } else {
    Write-Host "User: $User Does not exist on Site: $Site/$SiteCollection"


PS > Remove-SPUser.ps1 -Site http://wss -SiteCollection Test -User Domain\User

PS > Remove-SPUser.ps1 -help
share|improve this answer
Yours is good too. Almost exactly same as what default suggested. Thanks – Rosie O'Donnell Nov 14 '11 at 19:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.