Wednesday, April 8, 2015

How to Remove invalid users from SharePoint Web Applications


Here is a PowerShell script to remove invalid users from the SharePoint Web Applications

 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Get all the Site Collections inside the Web Application
$SiteColl = Get-SPWebApplication "http://abc.xyz.com" | Get-SPSite -Limit All
 
#Define the List of Users
$Users =@('domain\abc',’domain\xyz’)

#Iterate through all the Site Collections
foreach($site in $SiteColl)
{
 #Iterate through users to Remove
 foreach($user in $Users)
 {
   #Check if User Exists in Site
   if ($Site.RootWeb.SiteUsers | Where {$_.LoginName -eq $User})
   {
      $Site.RootWeb.SiteUsers.Remove($User)
   Write-Host "$($user) has been Removed from the $($Site.RootWeb.URL)"
   }
  }
}

Friday, April 3, 2015

How to Remove a User from a SharePoint 2013 Site Collection


As I was troubleshooting a recent issue with the User display name, where there was an change to a user account in Active Directory (like change in the last Name) . However, the change did not reflect in the site collection as expected.  Verified Profile sync and the last name is correct in the profile.

Here are the steps that I performed to fix the issue.

1.      As a site collection administrator, click Site Actions –> Site Permissions

2.      Click into any existing SharePoint group and the URL will be something like http://server/_layouts/people.aspx?MembershipGroupID=298.

3.      Change the 298 to a 0 and the list should now show you All People.

4.      Find the user whose last name is an issue, click the checkbox by their name.  Click Actions, Delete Users from Site Collection.

5.
      
Now add the user back to the appropriate group and you would notice the correct last name as expected.