Wednesday, July 29, 2015

0x80070003 error on Restore-SPSite when restoring a SharePoint 2013



The below error comes because of two main reasons.










  1.  When SharePoint versions are different from the source of the back to restore server.
  2.  Another reason is due to Content Database not updated.

When you have different versions you need to make sure that you have same version else if you have latest version of SharePoint running and your back is of older version make sure to upgrade the database and then restore the site collection using PowerShell.

First run the Upgrade-SPContentDatabase WSS_Content.  

Take the site collection backup and then restore. 

This will hopefully help you get rid of InvalidData error in Restoration of Site Collection.






Monday, July 27, 2015

Common issues and their resolution while installing SharePoint 2013 Server





Most of the times we face certain issues in installing SharePoint 2013 Server on Windows 2008 R2 or on Windows Server 2012.

I have described below issues with their solutions which I have faced every time I install SP 2013. 

1. Enabling .Net 3.5 on Windows Server 2012: Since Windows Server 2012 already has .Net framework 4.5 installed so we need below command to be executed in Command Prompt (Run as Administrator) after mounting Windows Server 2012 installation disk to enable .Net 3.5.
 Dism /online /enable-feature /featurename:NetFX3 /All    /Source:D:\sources\SxS                    /LimitAccess (Where D: is the location where Windows Server 2012 is mounted). 

2. SharePoint 2013: The tool was unable to install Application Server Role, Web Server (IIS) Role: This issue occurs due to the fact that the installer is locating the installer is trying to run the executable C:\Windows\System32\ServerManagerCMD.exe – which is not there in System32 directory. However, you will find ServerManager.exe, just copy this .exe file and paste. Then, rename SystemManager.exe to SystemManagerCMD.exe and try to run the PrerequisiteInstaller.exe. 

3. Installing AppFabric Cache for SharePoint 2013: In order to install Windows AppFabric Cache try to use Command Prompt (Run As Administrator) and execute below command instead of executing AppFabric Cache manually. Copy the Windows AppFabric Cache file in Prerequisite Installer Folder in SharePoint 2013 Installation Folder.
 
 

Then on Command Prompt access that location and then run the below command:  

prerequisiteinstaller.exe /AppFabric:WindowsServerAppFabricSetup_x64.exe


Thursday, July 9, 2015

User Profile Synchronization Service Hanging issue on Starting and can not be Stopped



Check List for User Profile Synchronization Service Hanging issue on Start / Stop & for proper UPS Service configuration

Below are some major causes of User Profile Service hangs on start or stop and also if any of these checks fail then user won’t be able to provision User Profile Service.

1.       If User Profile Synchronization (UPS) Service is in the state of “Starting” or “Stopping”, user below Power Shell commands to bring it in Stopped mode.
Get-spserviceinstance
Stop-spserviceinstance <GUID> Where GUID is the service id of UPS Service
2.       Now, UPS Service is in Stopped mode. Make sure that the UPS Service account is Farm Account and is in local admin group of the server having log on locally rights. To check this follow below steps.
To do this, go to Central Administration > Security > Configure service accounts:
·         Make sure that the Service account is a Farm account.
·         The Service account on the server should be the Local Administrator.
·         The Service account should have log on locally user rights on the server.
3.       To check user has log on locally rights, follow below steps.
·         Go to the Start menu and select > Run > secpol.msc
·         From the Local Security Policy window, select Security Settings > Local Policies > User Rights Assignment > Allow log on locally.
·         Right-click Allow log on locally and select Properties to add a user
4.       Start menu and select > Run > gpupdate
5.       Also, make sure SharePoint Timer Job is running with same account i-e Farm Account with which you are running UPS Service.
6.       Now, make sure user has Full Control permissions on User Profile Service Application. Follow below steps to make sure this.
·         Go to Central Administration and select Application Management > Manage Service Applications > User Profile Service Application
·         From the Administrators for User Profile Service Application menu, check the appropriate Permissions for user checkboxes.
·         Click OK.
·         From the Connections Permissions for User Profile Service Application menu, check the appropriate Permissions for user checkboxes.
·         Click OK.
7.       Set the FIM Services to run as Local System
·         Start -> Run -> services.msc
·         Locate the two FIM Services: Forefront Identity Manager Service, Forefront Identity Manager Synchronization Service.
·         Edit properties and set it to run as Local System account.

8.       Once all of the above has been completed and verified, you will be able to start the User Profile Synchronization Service.
9.       If still you are unable to proceed perform step 1 to bring UPS service in “Stopped” mode and perform below check and try again.
10 Check the Certificates store on the server that runs the User Profile Synchronization Service and delete all the ForefrontIdentityManager certificates.
·         Start -> Run -> mmc
·         File -> Add / Remove Snap-in
·         Select Certificates -> Computer Account -> Finish -> Local Computer -> Finish -> OK
·         Expand Certificates -> Personal -> Certificates
·         Delete all ForefrontIdentityManager certificates (if you have tried to provision the UPS unsuccessfully several times, you will see more than one certificate).
·         Expand Certificates -> Trusted Root Certification Authorities -> Certificates
·         Delete all ForefrontIdentityManager certificates (if you have tried to provision the UPS unsuccessfully several times, you will see more than one certificate).

Good Luck. Hope this will help you get rid of UPS Service issues. Trust me 90% of UPS Service issues are just because of improper rights assigned to UPS Service Accounts.





Tuesday, July 7, 2015

Deleting all wsp files deployed within SharePoint

Sometimes if it is required to delete all deployed custom solutions with SharePoint Farm using Power Shell then below script can assist you to get the required job done.

[CmdletBinding()]
Param(
   [Parameter(Mandatory=$true,Position=1)]
   [bool]$Confirm
)

function LoadSharePointPowerShellEnvironment
{
    write-host "Setting up PowerShell environment for SharePoint"
    write-host
    Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
    write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green
    write-host
}

LoadSharePointPowerShellEnvironment

$AdminServiceName = "SPAdminV4"
$WasAdminServiceRunning = $true;

if ($(Get-Service $AdminServiceName).Status -eq "Stopped")
{
    write-host "[[STEP]] Starting SharePoint Administration Service since it is not already started."
    write-host

    $WasAdminServiceRunning = $false;
    Start-Service $AdminServiceName

    write-host "[[STEP]] SharePoint Administration Service Started"     write-host
}

Start-SPAssignment -Global;
$solutions = Get-SPSolution
foreach($solution in $solutions)
{
    if($solution -ne $null)
    {
        $solutionName = $solution.Name
        if($solution.Deployed)
        {
            Write-Host "Uninstalling solution $solutionName..." -ForegroundColor Yellow
            write-host
            if($solution.DeployedWebApplications.Count -gt 0)
            {
                Uninstall-SPSolution -Identity $solution -AllWebApplications -Confirm:$Confirm
            }
            else
            {
                Uninstall-SPSolution -Identity $solution -Local:$true -Confirm:$Confirm
            }
            do
            {
                  Start-Sleep 5;
                  $solution = Get-SPSolution $solution;
            } while($solution.JobExists -or $solution.Deployed)
            Write-Host "Unistalled solution $solutionName successfully."
            write-host
        }

        Write-Host "Removing solution $solutionName..."
        write-host
        Remove-SPSolution -Identity $solution -Confirm:$Confirm
        do
        {
              Start-Sleep 5;
              $solution = Get-SPSolution $solution -ErrorAction SilentlyContinue
        } while($solution -ne $null)
        Write-Host "Removed solution $solutionName successfully."
        write-host
    }
}
Stop-SPAssignment -Global;

if (-not $WasAdminServiceRunning)
{
    write-host "[[STEP]] Stopping SharePoint Administration Service."
    write-host
        Stop-Service $AdminServiceName
    write-host "[[STEP]] SharePoint Administration Service Stopped."
    write-host
}

Write-Host "Farm solution store cleanup finished"

Wednesday, May 27, 2015

How to Download Deployed WSP files from Central Administration Using PowerShell

Sometimes we don't have any backup of .wsp files which we have already deployed in Central Administration. In order to download already deployed .wsp file from Central Administration we can use below power shell to download and save the wsp file on any path.

$SPFarm = Get-SPFarm
$getWSP = $SPFarm.Solutions.Item(“dotnetsharepoint.wsp”).SolutionFile
$getWSP.SaveAs(“C:\dotnetsharepoint.wsp”)
- See more at: http://www.dotnetsharepoint.com/2014/05/how-to-download-wsp-file-central-admin.html#sthash.PsqQHcMD.dpuf
$SPFarm = Get-SPFarm
$getWSP = $SPFarm.Solutions.Item(“PackageName.wsp”).SolutionFile
$getWSP.SaveAs(“C:\dotnetsharepoint.wsp”)

Also, below is the power shell script to download all the deployed solutions in SharePoint Farm.


#Get reference to SharePoint farm
$farm = Get-SPFarm
#Location to save the solution files
$loc = “D:\solutions” #replace with your file location. Make sure that the folder is already created/existing
#Download all the solutions
foreach($solution in $farm.Solutions){
$solution = $farm.Solutions[$solution.Name]
$file = $solution.SolutionFile
$file.SaveAs($loc + ‘\’ + $solution.Name)
}
Write-Host “All the solutions are downloaded to $loc”

Note: Just need to create solutions folder in d driver or any where else and replace that path in $loc variable in above path

$SPFarm = Get-SPFarm
$getWSP = $SPFarm.Solutions.Item(“dotnetsharepoint.wsp”).SolutionFile
$getWSP.SaveAs(“C:\dotnetsharepoint.wsp”)
- See more at: http://www.dotnetsharepoint.com/2014/05/how-to-download-wsp-file-central-admin.html#sthash.PsqQHcMD.dpuf
$SPFarm = Get-SPFarm
$getWSP = $SPFarm.Solutions.Item(“dotnetsharepoint.wsp”).SolutionFile
$getWSP.SaveAs(“C:\dotnetsharepoint.wsp”)
- See more at: http://www.dotnetsharepoint.com/2014/05/how-to-download-wsp-file-central-admin.html#sthash.PsqQHcMD.dpuf

Sunday, February 15, 2015

Accodian Control in SharePoint 2013 Quick Launch Menu

Sometimes when we have too many links to be displayed in the left navigation (Quick Launch) menu then we need to implement Accodion Control to expand and shrink the links.
I came to same scenario while I was implementing one such solution for my intranet portal.
In order to implement we need to have below steps to follow :

Step 1 : Go to Site Settings > Look and Feel > Navigation
Step 2: Create Folder Say I.T Requests under Current Navigation and within this folder create multiple links such as Help Desk Request, I.T Security Guidelines, I.T Audit Policy i-e which will be shrink and expanded inside I.T Request folder.
Step 3: You can create multiple such folders and links inside Current Navigation.
Step 4: Now, we need to implement our solution.
Step 5: Now, open your master page's html file and copy below css under <head> tag
<!-- start here accordian panel --> 
<script type="text/javascript">
var SP2013QLAccordion = {
  // Options
  useAnimation: true, // Animation is supported in IE9+
  collapseOtherLevels: false, // Collapse sibling levels on expanding
  expandTransition: 'height 0.15s ease-out',
  collapseTransition: 'height 0.15s ease-out',
   
  // Initialization function
  init: function (){
    var levels = document.querySelectorAll('.ms-core-listMenu-verticalBox li');
   
    if (levels.length) {
      for (var i = 0; i < levels.length; i++) {
        if (levels[i].querySelector('ul')) {

          // Create switch elements and append them to levels with sublevels
          var switchSpan = document.createElement('div');
         
          switchSpan.className = 'switch';
          switchSpan.innerHTML = '<span><img alt="" src="/_layouts/15/images/spcommon.png"/></span>';
          levels[i].insertBefore(switchSpan, levels[i].firstChild);
         
          // Add 'expanded' class to selected branch and 'collapsed' to all other
          levels[i].className += (levels[i].querySelector('.selected') || levels[i].className.indexOf('selected') != -1) ? ' expanded' : ' collapsed';
        }
      }
   
      // Detect IE8 or lower to turn off animation
      if (document.all && !document.addEventListener) SP2013QLAccordion.useAnimation = false;
     
      var switches = document.querySelectorAll('.ms-core-listMenu-verticalBox .switch');
      // Add collapse/expand event to switch nodes
      if (switches.length) {
        for (var j = 0; j < switches.length; j++) {
          AddEvent(switches[j], 'click', ExpandCollapse);
        }
      }
    }

    // Function to get height of a hidden node
    function CalculateHeight (node) {
      var initialStyles = node.style.cssText,
        nodeHeight;
     
      node.style.position = 'absolute';
      node.style.visibility = 'hidden';
      node.style.height = 'auto';
      nodeHeight = node.offsetHeight;
      node.style.cssText = initialStyles;
      return nodeHeight;
    }

    // Expand/Collapse function
    function ExpandCollapse (param) {
      var level = this.parentNode,
        sublevel = level.querySelector('ul'),
        sublevelHeight = CalculateHeight(sublevel),
        otherLevels = level.parentElement.children;

      // Close other levels on expanding
      if (SP2013QLAccordion.collapseOtherLevels && level.className.indexOf('collapsed') != -1 && !param) {
        for (var i = 0; i < otherLevels.length; i++) {
          if (otherLevels[i].className.indexOf('expanded') != -1) ExpandCollapse.call(otherLevels[i], 'collapse');
        }
      }    
     
      if (SP2013QLAccordion.useAnimation) {
        // Animated collapse
        if (level.className.indexOf('expanded') != -1 || param == 'collapse') {
          sublevel.style.height = sublevelHeight + 'px';
          level.className = level.className.replace(' expanded',' collapsed');
          sublevel.style.transition = SP2013QLAccordion.collapseTransition;
          sublevel.offsetHeight; // Force repaint
          sublevel.style.height = 0;
        // Animated expand
        } else {
          sublevel.style.height = 0;
          level.className = level.className.replace(' collapsed',' expanded');
          sublevel.style.transition = SP2013QLAccordion.expandTransition;
          sublevel.offsetHeight; // Force repaint
          sublevel.style.height = sublevelHeight + 'px';
          sublevel.addEventListener('transitionend', function transitionEnd(event) {
            if (event.propertyName == 'height') {
              sublevel.removeAttribute('style');
              sublevel.removeEventListener('transitionend', transitionEnd, false);
            }
          }, false);
        }
      } else {
        // Not animated collapse
        if (level.className.indexOf('expanded') != -1 || param == 'collapse') {
          level.className = level.className.replace(' expanded',' collapsed');
        // Not animated expand
        } else {
          level.className = level.className.replace(' collapsed',' expanded');
        }
      }
    }

    // Crossbrowser event attachment helper function
    function AddEvent (htmlElement, eventName, eventFunction) {
      if (htmlElement.attachEvent)
        htmlElement.attachEvent("on" + eventName, function() {eventFunction.call(htmlElement);});
      else if (htmlElement.addEventListener)
        htmlElement.addEventListener(eventName, eventFunction, false);
    }
  }
};

// SharePoint default DOM onLoad function
ExecuteOrDelayUntilBodyLoaded(SP2013QLAccordion.init);
</script>
<!-- end here accordian panel -->
Step 6 : Go to url : http://yakovenkomax.com/converting-sharepoint-2013-quick-launch-to-accordion-menu/
Step 7: Download the JQuery file and upload that in SharePoint.
Step 8: Refer the JQuery File Path in Master Page's html file like <link rel="stylesheet" type="text/css" href="css/SP2013Accordion.css" />.
Step 9: Check in the files and refresh the broswer you shall have accodion implemented in your left navigation / Quick Launch menu.

Finally, I must say I have implemented these steps by follow article placed here : http://yakovenkomax.com/converting-sharepoint-2013-quick-launch-to-accordion-menu/.

.