10

Is there a way I can choose to remove a single user from all site collections within a single web application using powershell. There are number of user profiles whose domain account has been blocked or removed from the AD as such they need to be removed from the SharePoint sites as well.

I want a powershell script like this which takes two inputs :

removeuser.ps1 -webapplicationurl -domain\userid

On running this script , I should be able to delete the user (domain\userid) from all site collections with in the web application. Seeking someone to help me achieve this.

I have SharePoint 2010 and the solution I require needs to be 2010 compatible. Thanks in advance.

1
  • is there a way to make an output with the results for this? just a text file would work.
    – user17313
    Commented May 29, 2013 at 15:24

1 Answer 1

11

Can't test it myself but it wouldbe something like this:

######################## Start Variables ########################
$LoginName = "domain\login"
$siteURL = "http://SharePointSiteURL" #URL to any site in the web application.
######################## End Variables ########################
Clear-Host
$siteCount = 0
[system.reflection.assembly]::loadwithpartialname("Microsoft.SharePoint")
$site = new-object microsoft.sharepoint.spsite($siteURL)
$webApp = $site.webapplication
$allSites = $webApp.sites
foreach ($site in $allSites)
{

    $web = $site.openweb()
    $web.SiteUsers.Remove($LoginName)
    $web.Dispose()
    $siteCount++
}
$site.dispose()
write-host "Updated" $siteCount "Site Collections."
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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