Tuesday, June 23, 2015

Clear SharePoint Config cache data on the servers

Sometimes we need to clear the config cache data on the SharePoint servers which supposed to be fixed or we are trying to fix fetching old configured data from the servers. Like we do dns flush, same way we need to clear the config cached data for SharePoint.
Below are the steps to clear the cache:-

1) STOP the timer service manually
2) Run the following powershell script below to clear the config cached data
--------------------------------------------------------------------------------------------------------------------------
Write-Host "This script clears your SharePoint config cache on this server. This should be done on all servers simultaneously.";
$confirm = Read-Host "Have you stopped the timer service on all SharePoint servers? y or n"
If ($confirm -eq "y" -or $confirm -eq "yes" ) {
                Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
                               
                #Retrieve the ID of the configuration database from the registry. This ID identifies the caching folder on disc.
                $ConfigDb = (Get-SPDatabase | Where {$_.TypeName -eq "Configuration Database"}).ID
                $ConfigDbId = $ConfigDb.GUID

                # Creating the folder path
                $CacheFolder = Join-Path -Path ([Environment]::GetFolderPath("CommonApplicationData")) -ChildPath "Microsoft\SharePoint\Config\$($ConfigDbId)"

                # Clearing out the cache
                Write-Host "$env:COMPUTERNAME - Clearing cache folder"
                Get-ChildItem "$CacheFolder\*" -Filter *.xml | Remove-Item
                Get-ChildItem "$CacheFolder\*" -Filter *.tmp | Remove-Item

                # Locate the cache ini file and reset it by writing the value '1' into the file.
                Write-Host "$env:COMPUTERNAME - Resetting cache ini file"
                $CacheIni = Get-Item "$CacheFolder\Cache.ini"
                Set-Content -Path $CacheIni -Value "1"

                Write-Host "Please confirm Cache.ini is reset to '1' and XML/TMP files have been removed. The explorer window should open shortly (~25 seconds)."
                Start-Sleep -Seconds 25
                $ShellExp = new-object -comObject Shell.Application
                $ShellExp.open($CacheFolder);

                Write-Host "Config cache has been cleared. Please start the timer service and confirm that the XML files are re-populating."
}
Else {
                Write-Host "Script has been canceled."
}
-----------------------------------------------------------------------------------------------------------------------
3) Restart the Timer service once above script is executed successfully.

The script will also open up the explorer window with cache files location and will see repopulating the directory with new files

Powershell to get all users in Owners group of site collection and sub-sites

If you want to get the users name, information for all the owners in a site collection and export it to an excel sheet, follow the below powershell script to do that:-
-------------------------------------------------------------------------------------------------------
Add-PsSnapin Microsoft.SharePoint.PowerShell


Start-SPAssignment -Global


Get-SPSite http://yoursite/
Get-SPWeb -Limit All |
  where { $_.HasUniquePerm -and $_.AssociatedOwnerGroup -ne $null } |
  foreach { $TTNweburl = $_.Url; $_ } |
  Select -ExpandProperty AssociatedOwnerGroup |
  Select -ExpandProperty Users |
  Select {$TTNweburl}, UserLogin, DisplayName | Export-Csv -Path d:\output.csv -Encoding         ascii -NoTypeInformation

Stop-SPAssignment -Global
----------------------------------------------------------------------------------------------------------------
above script will list all the users and save the output in a csv file in provided location.
Text in bold above needs to be changed with your environment changes.

Tuesday, May 12, 2015

Upgrade is currently disabled for your site collection

You get the message that upgrade is currently disabled when you try to do site collection upgrade option under Site Collection administration or you try with Powershell.

Use the below command in powershell to enable the site for upgrading.

$site=Get-SPSite "http://SPSITE"
$site.AllowSelfServiceUpgrade=$true

How to deploy WSP Solution in compatibility mode using powershell

As there is no option in Central Administration to deploy a solution in Compatibilty mode, we can use powershell to deploy a solution.

The Suggested method for this type of deployment is:-

Install-SPSolution –Identity Solution.wsp –GACDeployment –CompatibilityLevel {14,15}

Wednesday, April 29, 2015

How to change account for Distributed Cache Service in SP 2013?

One need to have managed account to run the distributed cache serverice under that. Below is the powershell command to change or run the service:-


$farm = Get-SPFarm
$cacheService = $farm.Services | where {$_.Name -eq "AppFabricCachingService"}
$accnt = Get-SPManagedAccount -Identity domain_name\user_name
$cacheService.ProcessIdentity.CurrentIdentityType = "SpecificUser"
$cacheService.ProcessIdentity.ManagedAccount = $accnt
$cacheService.ProcessIdentity.Update() 
$cacheService.ProcessIdentity.Deploy()


You can also Start the service as below:-

Add-SPDistributedCacheServiceInstance

and to remove a Cache host:-


Remove-SPDistributedCacheServiceInstance

Friday, March 27, 2015

Sign in as different user in SharePoint 2013

Sign in as different user has been removed from the SharePoint 2013 could be because of the users switching between accounts and making customizations to the existing page directly.


below is the way we can make it appear on the SharePoint sites:-


  • Locate the file \15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx and open in a text editor.
  •  Add the following element below the existing element "ID_PersonalInformation"


    <SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"
     Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"
     Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"
     MenuGroupId="100"
     Sequence="100"
     UseShortId="true"
     />


    And Now save the file. Do it on all the SP servers. Refresh the site now and you should be able to see it.

    Thursday, March 5, 2015

    How to schedule automatic backup of a site collection?

    To Schedule automatic backup of the site, you need to have your powershell script ready which we will schedule as below. You can have the script from here:-
    http://sharepointfamily.blogspot.com/2015/03/how-to-backup-site-collection-in.html

    1) Copy your ps1 file in some directory where you want to take backup every night.
    2) Go to Windows Task Scheduler and create a new JOB in it.ex- SiteBackup
    3) Under Task properties, you can set job to run for a given time under Triggers.
    4) Under Actions, select Start a Program and under programs\cripts, we need to put path to powershell. Foe ex:- C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe. And under "Add arguments" put " -WindowStyle Hidden & 'c:\Backup\Backupsite.ps1' " () Path to the saved PS1 (powershell script for doing site backup).

    5) Then you need to give a username and password to run this task in thw windows scduler based on your time.
      Once done, Click OK and you are good to go. Site will be created everyday with datetime stamp.