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)
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)
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}
$OpenWeb.SiteUsers.Remove($User)
Write-Host "User: $User Successfully Removed from Site: $Site/$SiteCollection"
} else {
Write-Host "User: $User Does not exist on Site: $Site/$SiteCollection"
}
$SPSite.Dispose()
$OpenWeb.Dispose()
}
Usage:
PS > Remove-SPUser.ps1 -Site http://wss -SiteCollection Test -User Domain\User
PS > Remove-SPUser.ps1 -help
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/