Monday, March 13, 2017

Reset Search Index in SharePoint 2013 using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
 
#Get Search service application
$ssa = Get-SPEnterpriseSearchServiceApplication
 
#Content Source Name
$ContentSourceName "SPSite"
 
#Get the content source
$ContentSource = Get-SPEnterpriseSearchCrawlContentSource -Identity $ContentSourceName -SearchApplication $SSA
 
#Get Each Start Address
$StartAddresses $ContentSource.StartAddresses | ForEach-Object { $_.OriginalString }
 
#Clear Indexed content starts with custom contnet source
$ContentSource.StartAddresses.Clear()
 
#Re-add the start address to content source
ForEach ($Address in $StartAddresses ){ $ContentSource.StartAddresses.Add($Address) }

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered


Problem:
Recently I started facing this issue.
Whenever, I load the PowerShell ISE and Type the command to load the SharePoint PowerShell module, it starts throwing error

“The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.”
The same error comes up in the SharePoint Management Shell.

Solution:
You have someone who has the rights to run powershell add your user as SP Shell Admin.
Add-SPShellAdmin -username DOMAIN\YourUser

That's quite the nobrainer, but what happens if your user is already SPShellAdmin, shown with Get-SPShellAdmin and you get the same error popping up? In that case, something probably happened with the SQL. They restored the farm on another server and did not migrate all the access rights. Just run Add-SPShellAdmin -username DOMAIN\YourUser again and it will set the appropriate permissions.


Compare SPUser objects in SP code


I have to compare the User value in the Assigned To Field of the List with the other User value.
Here is the exact code that will do this.

SPUser spUser = GetSPUserOne();
SPUser spPrevUser = GetSPUserTwo();

For Windows Authentication This will do

if(spUser.Sid.Equals(spPrevUser.Sid))
{
…..
}

For FBA you have to follow this

if(spUser.UserToken.CompareUser(spPrevUser.UserToken))
{
…..
}

Friday, March 10, 2017

How to check the SharePoint Installation Type – Standalone or Farm

The solution is to launch the Registry Editor (regedit.exe) and check for the Server Role at the following location depending on the SharePoint version:

SharePoint 2007: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\WSS\ServerRole
SharePoint 2010: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\ServerRole
SharePoint 2013: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0\WSS\ServerRole

Tuesday, March 7, 2017

Enable custom erro in Web.config file in SharePoint

Every change you make in that config files have no effect on the web application. You have to go the web.config file that is generated once the web application is created.
So edit the web.config file in C:\inetpub\wwwroot\wss\VirtualDirectories\your port number and modify the parameters you have indicated in that web.config file:
·         customErrors mode must be "Off"
·         compilation debug must be "true"
·         SafeMode CallStack must be "true"

The 'your port number' piece of path is the