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

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


Please see the script below, it "Remove / Delete users from all sites and site collections within a web application.": http://blog.isaacblum.com/2011/02/24/remove-delete-users-from-all-sites-and-site-collections-within-a-web-application/

| improve this answer | |
  • 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
| 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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