Friday, October 16, 2015

Enabling “Sign in as a different user” option in SharePoint 2013

By default SharePoint 2013 doesn’t provide option for sign in as a different user unlike we had option in SharePoint 2010 ribbon.





Microsoft has removed this option in SharePoint 2013 because of Caching problems, Documents opened in external applications are saved with an unexpected user account and many more.
In order to enable this option we need to follow below steps:
Step 1: Go to 
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATES\CONTROLTEMPLEATS.

Here we have a file named welcome.ascx.





Step: 2
Open welcome.ascx in Visual Studio or in Notepad and add the following code and save:
<SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"
  Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
  Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
  MenuGroupId="100"
  Sequence="100"
  UseShortId="true"
  />




And it should be above the tag which has ID_RequestAcess.
Step: 3
Refresh the site, and it's been enabled:

Saturday, October 3, 2015

Databases Running in Compatibility Range, Upgraded Recommended

If you are running SharePoint 2013 and SharePoint Health Analyzer has thrown "Database Running in Compatibility Range, Upgraded Recommended" issue then below is the fix to get rid of this issue.

The reasons of issuing this error are probably you have migrated SharePoint Server from SharePoint 2010 to SharePoint 2013 or you have installed March 2013 SharePoint Uber Update.
In either case this issue is being thrown by SharePoint Health Analyzer.

1. Run SharePoint 2013 Management Shell (Obviously Run As Administrator)

2. Paste the command "PSConfig.exe -cmd upgrade -inplace b2b -force -cmd applicationcontent 
-install -cmd installfeatures" and press enter.

3. This will take few minutes to complete.

4. Go to Error and Reanalyze. This will resolve the issue. However, you may this may complain the ContentDB upgrade issue which you can resolve by using "Upgrade-SPContentDatabase" and then enter the name of the ContentDatabase.









Bulk User Profile Deletion in SharePoint 2010 / 2013

Sometimes we are not sure about which AD objects to be imported from Active Directory to SharePoint and later when we come to know AD objects we need to delete existing imported profiles and re run the full synchronization.
In order to delete existing profiles below Power shell script will help us to delete all profiles except Farm Account from SharePoint User Profile.

PowerShell Script - Delete All User Profiles - SharePoint 2010 / SharePoint 2013
#The scripts is distributet "as-is." Use it on your own risk. The author give no warranties, guarantees or conditions.
#Add SharePoint PowerShell SnapIn if not already added

 if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
  Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

#Set my site host location. In this example I use host location on the same web application as the portal itself.
#MS recommends to use different web application for hosting your personal sites
#In this example My Site Host is on location http://sp2010/my/mysite/

$site = new-object Microsoft.SharePoint.SPSite("sp2010/my/mysite/");
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);

#Get UserProfileManager from the My Site Host Site context

$ProfileManager=new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)
$AllProfiles = $ProfileManager.GetEnumerator()
foreach($profile in $AllProfiles)
{
$DisplayName = $profile.DisplayName
$AccountName=   $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value

#Do not delete setup (admin) account from user profiles. In this case account is Domain\XYZ

 if($AccountName -ne " Domain\XYZ ")
{
$ProfileManager.RemoveUserProfile($AccountName);
write-host "Profile for account ", $AccountName, " has been removed"
}
}
write-host "Finished."

$site.Dispose()