Friday, May 30, 2014

Export SharePoint 2007 Search Crawl Log Errors using PowerShell

Requirement: Found so many errors logged in the Search crawl log. Wanted to analyze them.

Solution: Lets use this PowerShell Script to export search crawl errors to CSV:
 #Load SharePoint Assemblies
 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")
 
 #Web Application URL
 $url = "http://sharepoint.crescent.com"
 $csID = 4  #Content source id - Local SharePoint sites
      
 #Objects to get Crawl History
 $site = new-Object Microsoft.SharePoint.SPSite($url);
 $context = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($site);
 $logViewer = new-object Microsoft.Office.Server.Search.Administration.logviewer ($context)
   
 $crawlLogFilters = New-Object Microsoft.Office.Server.Search.Administration.CrawlLogFilters
 
 $EndDate = [System.DateTime]::Now
 $StartDate=$endDate.AddDays(-1)
 
 #Content Source Id
 $csProp=[Microsoft.Office.Server.Search.Administration.CrawlLogFilterProperty]::ContentSourceId 
 $crawlLogFilters.AddFilter($csProp, $csID)
 #Get all Errors
 $crawlLogFilters.AddFilter([Microsoft.Office.Server.Search.Administration.MessageType]::Error)  
 #Add Start Date and End Date
 $crawlLogFilters.AddFilter($startDate, $endDate)
 
$startNum = 0
$errorItems += $logViewer.GetCurrentCrawlLogData($crawlLogFilters, ([ref] $startNum))

while($startNum -ne -1)
{
  $crawlLogFilters.AddFilter(“StartAt”, $startNum)
  $startNum = 0; 
  $errorItems += $logViewer.GetCurrentCrawlLogData($crawlLogFilters, ([ref] $startNum))
  #Write-Host "Processing $startNum";
}

$errorItems | Export-CSV "d:\Backup\crawllog.csv" -notypeinformation


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, May 28, 2014

How to Integrate Google Analytics with SharePoint 2013

Google Analytics is a popular free service for website analytics. Why don't we use Google analytics with our SharePoint sites? Here is how to add Google analytics to SharePoint 2013:

Step 1: Sign-up & Get Google analytics Tracking code
You need to have a Google analytics account sto start with! Signup for the Google analytics account at: http://www.google.com/analytics/,  Login to Google analytics site, Navigate to "Admin" tab and setup new property for your web site by filling the farm, Click on "Get Tracking ID" button to generate  Google analytics tracking code for SharePoint. We need this tracking code to add google analytics to sharepoint site.
google analytics sharepoint integration
 You'll get tracking code something like:
install google analytics sharepoint 2013
Step 2: Edit Master page and Add Google analytics tracking code
Next step is to add Google analytics to SharePoint master page. Edit your master page in 'Advanced mode' with SharePoint designer 2013 and insert this code just before </head> tag.
google analytics in sharepoint master page
Save-Check-in-publish/Approve the master page.

Step 3: view Google analytics data for SharePoint
Wait for 24 Hours and you should see Google Analytics statistics populated based on your site's traffic.
Can I have Google analytics for SharePoint intranet sites?
How Google analytics works? Well, every time when users access the site, Google script runs on their browsers and registers the hit with Google Analytics along with some analytics data. So it doesn't matter even if your website is an intranet site, as long as the user viewing it has access to internet network to reach Google Analytics servers.

Google analytics vs SharePoint analytics:
We all know SharePoint already has some built-in usage analysis capabilities. Why we need Google analytics still? Well, Google Analytics extends these OOTB capabilities and provides more data such as: Say, you have a public internet SharePoint site and want to track which country your visitors are coming from, What they are looking for? How did they get to your site, What browsers they are using, etc.

You can use this technique to integrate google analytics with any version of SharePoint such as SharePoint 2010, SharePoint online, SharePoint foundation, etc.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Create Redirect (URL Shortcut) to a Subsite in SharePoint

Requirement:
We've a sub-site located at the URL - http://sharepoint.crescent.com/sites/marketing/regions/us/brandcenter/ and the requirement is to create a shortcut to this subsite. That is the URL shortcut: http://brandcenter.com should redirect to the above subsite.

Solution: To redirect to a subsite in sharepoint, lets use IIS HTTP Redirect module. Follow these steps to redirect to subsite.
Make sure HTTP Redirection module is installed before proceeding. If not, enable it from Server Manager!

Step 1: Create necessary DNS entries for your new host name.
To begin with, create DNS entries for your new host (in my case: http://brandcenter.com). It could be a HOST-A Record / Forward Lookup Zone / CNAME, etc based on your requirement. For testing purpose, you can make an entry in your HOST file (located at: C:\Windows\System32\drivers\etc)

Step 2: Create New IIS Web Site:
  • Go to IIS of your SharePoint Web front end server(s), Right click "Sites" node create a new site by choosing "Add Web Site"redirect sharepoint site to a subsite
  • Set the site name, Application Pool, Physical path accordingly. Host header as your new host name. Click on "Test Settings" button to make sure your application pool account is able to access the virtual directory and authentication works as expected.sharepoint 2010 redirect from root to subsite
Step 3: Configure HTTP Redirect Module in IIS
Now, Open the "HTTP Redirect" module from the IIS Site you have created.
sharepoint 2010 redirect from root to subsite
Enable "Redirect requests to this destination" check box and enter the full URL of your subsite. Enable "Redirect all requests to exact destination" check box also.
How to redirect to a subsite in sharepoint
Its also possible to use Tokens in the URL, such as: $S = Path, $Q = Query String.

That's all! Now, when a user hit http://brandcenter.com, they'll be redirected to: http://sharepoint.crescent.com/sites/marketing/regions/us/brandcenter/
Its also possible to manage all these things using the command line: AppCmd .Refer: http://blogs.msdn.com/b/mcsnoiwb/archive/2012/04/20/configure-redirect-via-iis-using-command-line-script.aspx

PowerShell script to set IIS HTTP Redirect:
import-module webAdministration

#Set these variables: Site name and Redirect URL 
$SiteName = "BrandCenter"
$RedirectURL = "http://sharepoint.crescent.com/sites/marketing/regions/us/brandcenter/"
 
# Set the redirect
Set-WebConfiguration system.webServer/httpRedirect "IIS:\sites\$siteName" -Value @{enabled="true";destination="$RedirectURL";exactDestination="true";httpResponseStatus="Found"}
This trick works on SharePoint 2007, SharePoint 2010 and SharePoint 2013 to redirect to sub site URL.


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, May 26, 2014

Default View Missing - Incremental Search Crawl Stuck - Solution

Problem: SharePoint incremental crawl stuck at a particular point of time - without changing the crawling status from: "Crawling Incremental". No progress in search crawl log. No new items included in search crawl.

Root cause: Default view files / associations missing in some of the lists and libraries. When crawler crawls those lists and libraries it just stuck there! I tried browsing those lists and libraries from "View all Site content" page. Found those libraries were pointing to their settings page, instead of "AllItems.aspx"!

Solution: Create a Default View using PowerShell:
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Get-SPWebApplication, Get-SPWeb cmdlets for MOSS 2007
Function global:Get-SPWebApplication($WebAppURL)
{
 return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
}

Function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();        
            }
    return $web
}

#Array to Hold Result - PSObjects
$ResultsColl = @()

$WebApp = Get-SPWebApplication "http://sharepoint.crescent.com"

#Get All site collections of the Web Application 
  $SitesColl = $webApp.Sites 
   
  #Iterate through each site collection/sub-site
  foreach($Site in $SitesColl)
  {
    foreach($web in $site.AllWebs)
       {    
          foreach($list in $web.lists) #Lable for Processing all lists. Otherwise, we'll get collection modified error
            {
                if($list.hidden -eq $false)
                 {
                    if($list.defaultview -eq $null)
                    {
                     write-host $web.URL - List Name: $list.title
                     
                     $ResultItem = New-Object PSObject
                     $ResultItem | Add-Member -MemberType NoteProperty -name "WebURL" -value $web.URL 
                     $ResultItem | Add-Member -MemberType NoteProperty -Name "ListName" -value $list.title

                     #Add the object with property to an Array
                     $ResultsColl += $ResultItem
                    }
                 }
             }
             $web.dispose()
       }
        $site.dispose()
    }
  
#Process Each List and Create a View in them
#We need to process each list in this separate section 
#Because, modifying any object in the collection will thorw: Collection modified exception

foreach($Result in $ResultsColl)
{
    $web = Get-SPWeb $Result.WebURL
    $list = $web.Lists[$Result.ListName]
    
    #Create the default view
    $BaseView = $list.GetUncustomizedViewByBaseViewId(0); # Standard View
    $viewColl = $BaseView.ViewFields.ToStringCollection();
    $list.Views.Add("Default", $viewColl, $BaseView.Query, $BaseView.RowLimit, $BaseView.Paged, $true);
    
    $web.dispose();
}

#Export the result Array to CSV file
$ResultsColl | Export-CSV "D:\NoDefaultView.csv" -NoTypeInformation 
   
write-host "Script execution has been Completed!"
The above script creates default view on list where its missing. Run the script and initiate a crawl again.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, May 24, 2014

Configure Self Service Site Creation in SharePoint 2013

What is Self Service Site Creation in SharePoint?
To create a new Site collection in SharePoint, Usually SharePoint Administrators use SharePoint Central Administration site or SharePoint Management Shell. Self-Service Site Creation feature enables end users to create site collections within a particular web application on their own. Self service site creation is not enabled by default. For "My Site" host web application, it should be enabled in order to provision SharePoint My Sites.

In a project collaboration environment, We had a requirement to enable end-users to create their own Site collections without the help of a SharePoint administrators.

How to enable self service site creation in SharePoint 2013:
You can enable/disable SSC in these three ways:
  1. Using SharePoint central admin to configure Self service site creation in SharePoint 2013
  2. Using PowerShell to enable self service site creation in SharePoint
  3. Using STSADM to enable self service site creation
Using Central Admin to Configure Self Service Site Creation in SharePoint 2013:
Go to your SharePoint 2010/2013 central administration site >> Application Management >> Manage Web Applications >> Select your target web application >> Click on "Self-Service Site Creation" button from the ribbon.
sharepoint self service site creation 2013
Its a best practice to set quota and specific managed path for Self Service Site Creation - So that we can keep users in control.

How to enable Self-Service site creation using STSADM:
stsadm -o enablessc -url http://crescent.com

This enables self service site creation in SharePoint 2013. You can disable self site creation SharePoint 2010 using Stsadm:
stsadm -o disablessc -url http://crescent.com

Enable self service site creation SharePoint 2010 with PowerShell:
Add-PSSnapin Microsoft.SharePoint.Powershell

# Enable Self Service Site Creation 
Write-Host "Enabling Self Service Site Creation..."
$WebApp = Get-SPWebApplication "http://crescent.com"
#sharepoint 2013 enable self service site creation powershell 
$webApp.SelfServiceSiteCreationEnabled = $true
$webApp.RequireContactForSelfServiceSiteCreation = $false
$webApp.Update() 

SharePoint self service site creation link
Once SSC is enabled, users get a "New Site" link in their My Sites.
You can directly access Self Service Site creation page URL at: http://your-sharepoint-web-app/_layouts/15/scsignup.aspx

Create Self Service Site programmatically with PowerShell:
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Configuration Variables
$WebAppURL ="http://crescent.com" 

$SiteCollectionUrl ="http://crescent.com/projects/sales"
$SiteTitle="Sales Site" 
$Description=""
$Locale="1033"
$Template ="STS#0"
$AdminLogin="crescent\SP_Farm"
$AdminName="Farm Account"
$AdminEmail="SP_Farm@crescent.com"
$SecondaryAdminLogin="crescent\SP_Setup"
$SecondaryAdminName="Setup Account"
$SecondaryAdminEmail="SP_setup@crescent.com"

$RootSite = Get-SPSite $WebAppURL

$RootSite.SelfServiceCreateSite($SiteCollectionUrl, $SiteTitle, $Description, $locale, $template, $AdminLogin, $AdminName ,$AdminEmail, $SecondaryAdminLogin, $SecondaryAdminName, $SecondaryAdminEmail)
You may get: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) error while creating SharePoint self service site programmatically, if you don't have enough access.

 

SharePoint self service site creation permissions:

Once self service site creation is enabled, Any user can create site collections from their My Sites! However, its possible to restrict this feature within a particular group of people, Say for e.g. You may want to limit this feature availability only with in a particular team. (provided, that specific team has a Active directory security group!).

Step 1: Remove "Self Service Site Creation" from user permissions.
Go to Central administration >> Application Management >> Manage Web Applications >> Select your target web application >> Click on "User Permissions" icon from the ribbon >> Scroll down and remove "Self Service Site Creation" permission.
 sharepoint self service site creation permission
Step 2: Create new permission policy with "Self service site creation" access.
From the Manage web applications page, Click on "Permission Policy" >> Add Permission Level Policy >> Give it a name and description, (I've named it as: Self Site Creators - Users who can Create Site collections) Choose "Self service site creation" access and Click "OK" to save your changes.


 sharepoint 2010 self service site creation permission

Step 3: Add a web application user policy to assign the permission policy created to required user group.
We've the permission policy ready. Now, the last step is to add a web application user policy by clicking "User Policy" from the ribbon >> Click on "Add Users" >> Select "All Zones", Click Next >> Specify the relevant group allowed  to create site collections through self site creation. Choose the permission policy created (Self Site Creators - Users who can Create Site collections).


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, May 23, 2014

Upload Master Page to SharePoint using PowerShell

Requirement:
We've a SharePoint 2013 master page from a third-party consultants and would like copy-apply the master page to SharePoint sites.

PowerShell script to upload Master page to SharePoint:
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$WebURL = "https://intranet.crescent.com/"
$MasterPage = "Crescentv1.master"
$SourcePath ="D:\Branding\MasterPages\Crescentv1.master"

#Get the Web
$web = Get-SPWeb $WebURL

#Get the Target folder - Master page Gallery
$MasterPageList = $web.GetFolder("Master Page Gallery")

#Set the Target file for Master page
$TargetPath = $Web.Url + "/_catalogs/masterpage/Crescentv1.master"

#Get the Master page from local disk 
$MasterPageFile = (Get-ChildItem $SourcePath).OpenRead()

 #Check if file exist already
 if ($Web.GetFile($TargetPath).Exists)
  {
    $Web.GetFile($TargetPath).recycle() 
  }

    #upload master page using powershell
    $MasterPage = $MasterPageList.Files.Add($TargetPath,$MasterPageFile,$false)
     
    $web.Update()          
This script copies master page to SharePoint from local disk. Just wrap the code inside a loop to copy the master page to all sites. Once uploaded, we can Set the master page with another PowerShell script:  Change Master Page in SharePoint using PowerShell


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, May 22, 2014

Storage Analysis Report for SharePoint Document Library

Requirement: On a very large document library, We needed to analyze all documents stored, in-order-to move documents into individual libraries/folders, as this larger library causing latency issues. Lets use PowerShell script to analyze and generate report on document library storage information:

PowerShell script to generate storage metrics report on SharePoint library:
#Get Size of all Sub-sites in a Site Collection
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#For MOSS 2007 compatibility
Function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb()        
            }
    return $web
}
 
# Function to Get Storage Metrics for a Library 
Function GetStorageMetrics($Folder)
{
    #Array to hold Storage data for all files
    $StorageDataCollection = @()
    
    foreach ($File in $Folder.Files)
    {
        #Get File Size
        $FileSize = $File.TotalLength
        
        $VersionSize = 0
        #Get the Versions Size
        foreach ($FileVersion in $File.Versions)
        {
            $VersionSize +=$FileVersion.Size
        }
        $TotalFileSize = $FileSize + $VersionSize
  
        #Create an object to hold storage data
        $StorageDataResult = New-Object PSObject
        #Set storage details to object property 
        $StorageDataResult | Add-Member -type NoteProperty -name "File Name" -value $File.Name
        $StorageDataResult | Add-Member -type NoteProperty -name "File Size (KB)" -value ([Math]::Round(($FileSize/1KB),2))
        $StorageDataResult | Add-Member -type NoteProperty -name "Versions Size (KB)" -value ([Math]::Round(($VersionSize/1KB),2))
        $StorageDataResult | Add-Member -type NoteProperty -name "Total File Size (MB)" -value ([Math]::Round(($TotalFileSize/1MB),2))
        $StorageDataResult | Add-Member -type NoteProperty -name "File Type" -value $File.Item['File Type'] 
        $StorageDataResult | Add-Member -type NoteProperty -name "Created on" -value $File.TimeCreated 
        $StorageDataResult | Add-Member -type NoteProperty -name "Last Modified" -value $File.TimeLastModified 
        $StorageDataResult | Add-Member -type NoteProperty -name "Created by" -value $File.Author.Name        
        $StorageDataResult | Add-Member -type NoteProperty -name "Parent Folder" -value $File.ParentFolder

        $StorageDataCollection += $StorageDataResult
        #Write-Host "Processing File:"$File.Name
    }
 
      #Get Files in Sub Folders
        foreach ($SubFolder in $Folder.SubFolders)
        {   
         if($SubFolder.Name -ne "Forms") #Leave "Forms" Folder which has List default Aspx Pages.
             {
                GetStorageMetrics($SubFolder)          
             }
        } 

       #return [Math]::Round(($FolderSize/1MB),2)    
    return $StorageDataCollection
}

#Set Site URL and Library name variables
$WebURL = "http://sharepoint.crescent.com/finance/"
$LibraryName = "Invoices"

#Get the Web where library exists
$Web = Get-SPWeb $WebURL
 
#Get the Library's Root Folder
$Library =  $Web.Lists[$LibraryName].RootFolder
 
#Call the function to get library's detailed storage Metrics
$StorageDetails = GetStorageMetrics($Library)

write-host "Total Number of Files in the library:" $Web.Lists[$LibraryName].ItemCount 

#Get the Total size of the library
$TotalSize = ($StorageDetails | Measure-Object 'Total File Size (MB)' -Sum | Select -expand Sum)  
Write-host "Library Size in MB: "([Math]::Round($TotalSize,2))

#export the detailed storage Info the CSV file
$StorageDetails | sort-object "Total File Size (MB)" -descending | Export-csv "LibraryStroageRpt.csv" -notypeinformation
Write-host "Detailed Storage Report has been generated!"
      
$Web.dispose()
 
This script gives data back in CSV format,which we can open in Excel, add few more formatting to get the insights on where and what files occupying space and how we can categorize them.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Hide Quick Launch Bar in SharePoint 2013

How to hide SharePoint quick launch?
Want to remove the quick launch from SharePoint 2013 sites, perhaps to see the home page in full width? How to hide quick launch in SharePoint 2013?  Well, to enable or disable Quick Launch through the SharePoint 2013 user interface, Go to:
  • Site Settings >>  Under Look and Feel, click Tree view.
  • To disable quick launch, Simply uncheck the "Display Quick Launch"check box. To enable it, just do the reverse.
    quick launch sharepoint 2013 remove
You can programmatically do the same with PowerShell as: $web.QuickLaunchEnabled = $false.

But wait! Although unchecking the "Display Quick Launch" check box hides quick launch bar in SharePoint 2013, it leaves that space empty! So, lets seek help from CSS to hide quick launch SharePoint 2013.

CSS to Hide quick launch in SharePoint 2013:
  • Navigate to your SharePoint site >> Click on Edit the page from settings menu 
  • Click on Insert >> Add a script editor web part to a page.
  • Click EDIT SNIPPET and paste the below code in it:
    hide quick launch sharepoint 2013 css
 <style>
/* hide quick launch SharePoint 2013 */
#sideNavBox
    {
     display: none;
    }

/* adjust position of content */
#contentBox
 {
   margin-left:10px!important;
 }
</style>
  • Click Insert and the quick launch will disappear now.
SharePoint 2013 has "Focus on Content” feature which highlights the Content area by hiding the quick Launch and Top link bar.

Hide quick launch, Top link bar on a page in SharePoint 2013
Here are the Ids of DIVs in SharePoint page layout:
remove quick launch bar sharepoint 2013
  • Quick Launch menu id : sideNavBox
  • Top Link Bar id: titleAreaBox
  • Content Area id: contentBox
So, to hide the desired section, use the IDs in your CSS appropriately.

Please note, these CSS codes hide quick launch in SharePoint 2013 on page level. If your requirement is to hide the quick launch in SharePoint 2013 for the entire site, you got to make the same change in your master page or in page layout (by default its: seattle.master). Open your master page in SharePoint desinger, Insert the above code just below <body> tag. Save and approve your master page.

Related post: Hide Quick Launch (Left Navigation) in SharePoint 2010/MOSS 2007

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, May 21, 2014

Increase Maximum File Upload Size in SharePoint 2013

SharePoint 2013's default file upload size is 250 MB! To upload large files you have to change "Maximum Upload Size" setting in SharePoint 2013 Central administration site.

How to increase file upload size in SharePoint 2013?
Maximum upload size setting is configured per web application. To change maximum upload size in SharePoint 2013, do the following:
  • Browse to SharePoint 2013 Central Administration site
  • Navigate to Application Management >>Manage Web Applications 
  • Select your web application and click on Web Application General Settings in the ribbon
    sharepoint 2013 maximum file upload size
  • In the web application general settings page, you can set the "Maximum Upload Size" value to the value you desire (Say, you want to increase upload size to 500 MB!) and hit OK to save your changes.
    sharepoint 2013 upload size limit
This changes maximum upload size in SharePoint 2013. You can specify the maximum value up to 2 gigabytes (or 2047 megabytes as specified in Central Administration). 
In my SharePoint 2013- Windows Server 2012 R2 environment, This is the only change I've made to add support for large files. No more web.config edits, IIS changes! Just a Central Admin change worked fine!!

Set maximum upload file size in SharePoint 2013 using PowerShell:
SharePoint 2013 maximum upload file size can be set using PowerShell also. Here is how:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Set-MaxFileUploadSize($WebAppURL, $Size)
{
    #Get the web applicatiin 
    $WebApp =  Get-SPWebApplication | where {$_.url -eq $WebAppURL }

    If($WebApp)
    {
        #Increase Maxium File upload size
        $WebApp.MaximumFileSize = $Size
        $WebApp.update()
            
        write-host "Maximum File Upload Size has been updated to $($Size) MB!" -ForegroundColor Green
    }
    else
    {
        write-host "Could not find a web application with URL: $($WebAppURL)" -ForegroundColor red
    }
 }

 #Call the function to set max file upload size
 Set-MaxFileUploadSize "http://pmo.crescent.com" "500"

In some cases, You may have to adjust timeout, MaxRequestLength values in IIS and Web.config files. Here is the Microsoft KB article addressing this issue along with workarounds: http://support.microsoft.com/kb/925083

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Enable Anonymous Access in SharePoint using PowerShell

In continuation with my last post, How to Enable Anonymous Access in SharePoint 2013, Here are some nifty PowerShell scripts to manage anonymous access in SharePoint:

PowerShell script to Enable Anonymous Access settings of a Web Application:
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$webApp = Get-SPWebApplication 'http://sharepoint.crescent.com/'
$webApp.IisSettings['Default'].AllowAnonymous=$true
$webApp.update()

PowerShell to Set anonymous access on specific SharePoint sites:
$web = Get-SPWeb http://sharepoint.crescent.com/sites/operations
#Enabled -  lists and libraries; On - Entire web site ; Disabled - Self explanatory :-)
$web.AnonymousState = [Microsoft.SharePoint.SPWeb+WebAnonymousState]::Enabled 
$web.Update()

Enable anonymous access on all sites under a web application:
(Get-SPWebApplication http://sharepoint.crescent.com | Get-SPSite | Get-SPWeb | Where {$_ -ne $null -and $_.HasUniqueRoleAssignments -eq $true } ) | ForEach-Object { $_.AnonymousState = [Microsoft.SharePoint.SPWeb+WebAnonymousState]::On; $_.Update(); }

Enable Disable anonymous access at List or library level in SharePoint 2010:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$web = Get-SPWeb http://sharepoint.crescent.com/sites/operations

$list = $web.lists.tryGetList("Documents")
if($list -ne $null)
{
$list.BreakRoleInheritance($true)
$list.AllowEveryoneViewItems = $true
$list.AnonymousPermMask64 ="Open, OpenItems, ViewListItems, ViewVersions, ViewFormPages, ViewPages, UseClientIntegration"
$list.update();
}
To disable anonymous access, You can either set the Permission mask as:
$list.AnonymousPermMask64 ="EmptyMask" or reset inheritance by calling: $list.ResetRoleInheritance() 

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Enable Anonymous Access in SharePoint 2013

Setting up anonymous access in SharePoint sites is a common task for most us, Often we do it to enable anonymous access for SharePoint 2013 for public facing sites. Lets see the steps needed to configure anonymous access in SharePoint 2013. 

Enable anonymous access for SharePoint 2013 web application:
To enable anonymous access to an existing SharePoint 2013 site, we've to enable anonymous access at web application level first. Navigate to:
  • Central Administration >> Application Management >> Manage web applications
  • In the Web Application Management page, select your target web application. Now, from  ribbon click on "Authentication providers" buttonanonymous access SharePoint 2013
  • Click on the relevant zone from the authentication providers. In my case its "Default".
  • Check "Enable anonymous access" option in the authentication providers page. Scroll down and press the "Save" button to commit the changes.enable anonymous access SharePoint 2013
Once the web application is configured to allow anonymous access, We can adjust what permissions should be granted to anonymous users for the entire web application by setting anonymous policy.
  • If you want allow read-only access, set the anonymous policy accordingly:


But wait, we are not yet done! still users may get access denied even though we enabled it at web application level!!

Enable anonymous access SharePoint 2013 site
We've just allowed anonymous access to the web application, which doesn't mean all sites under the web application automatically gets anonymous access. Proceed with the next step.
  • Log in to your SharePoint site as a site collection administrator. Navigate to Site settings, Under the “Users and permissions” section, click the “site permissions".
  • Click on the Anonymous Access icon.set up anonymous access SharePoint 2013
  • Now, Select what part of the Web site anonymous users can access.SharePoint 2013 grant anonymous access
Here, your choices are: Entire Web Site, Lists And Libraries, or Nothing.
  1. If you select Entire Web Site, anonymous users will have read access to all content in this website and sub-sites that inherit permissions. 
  2. If you select Lists and Libraries, anonymous users have no access to the website and can only directly access lists or libraries where inheritance is broken and anonymous permissions have been granted. 
  3.  If you select Nothing, anonymous users have no access to any content in this website.
This turns on anonymous access in SharePoint 2013 with read-only access to all lists and libraries.
Now, you can click on
SharePoint 2013 publishing site anonymous access: Make sure you disable "Limited-access user permission lockdown mode" feature in site collection features section to allow anonymous to access SharePoint Lists or Libraries. This feature is activated by default in SharePoint 2013!

SharePoint 2013 anonymous access lists and libraries
There may be cases, where you want to enable anonymous access only to specific lists and library but not entire site. E.g. You may want to configure anonymous access to SharePoint 2013 survey. Here is now to Grant anonymous access to specific list/library:
  • Go back to Site settings >> Site Permissions page under site settings >> Users and Permissions tab.
  • Choose "Lists and Libraries" in site permission.sharepoint 2013 anonymous access document library
    It doesn't mean that Lists and libraries in the web application is accessible to Anonymous user. You must grant anonymous access to each list and library. Here is how:
  • Navigate to any List / Library to which you want to grant Anonymous access. 
  • Go to Library settings >>  Permissions for this document library >> Click on "Stop inheriting Permissions" under permissions tab. Now, you'll get "Anonymous Access" button in the ribbon.sharepoint 2013 anonymous access list
  • Click the relevant rights such as View items (These rights are enabled/disabled based on web application's anonymous policy!)
This allows anonymous access SharePoint 2013 list or library.
If you are setting a list’s permissions, your choices are Add Items, Edit Items, Delete Items, and View Items. If you are adjusting a library’s permissions, you can only grant View Items.

To enable anonymous access for SharePoint 2010, refer: How to Enable Anonymous Access in SharePoint 2010

Disable anonymous access SharePoint 2013
Simple! If you want to disable anonymous access at web application level, or site or list level, Just revert the steps discussed above. On Sites, Go to Site permissions page and set anonymous access to "Nothing"!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, May 17, 2014

Merge-SPLogFile: Merge SharePoint Log Files from Multiple Servers

Problem: In a multi-server SharePoint farm, if you need to trace an issue, you have to log-in and review the ULS logs on each server in the farm. This process could be tedious in multi-server farms since you're not sure on which server the error has occurred.

Solution: Use the Merge-SPLogFile PowerShell cmdlet.

The Merge-SPLogFile cmdlet will consolidate the logs from all servers in the SharePoint farm into a single log file. You can run it from any server and it gathers data from the entire farm - to find issues.

Here are some examples of Merge-SPLogFile:

Extract LOG from all SharePoint Servers matching correlation ID:
Merge-SPLogFile -path "D:\ErrorLog.txt" -Correlation "Your-error-correlation-id" 
Use the above cmdlet to fetch ULS log for given correlation ID from all SharePoint servers in a multi-server farm. Here "path" refers to the log file name you want to create. If it already exists, use "overwrite" switch. This cmdlet looks for logs within past 20 Minutes of time span.

Merge-SPLogFile -Path D:\ErrorLog.txt -StartTime "20/10/2014" -overwrite

We can use parameters such as StartTime and/or EndTime parameters to to specify the range of the log entries. There are other properties to help you narrow down the log search:
  • Area
  • Category
  • ContextFilter
  • Correlation
  • EndTime
  • EventID
  • Level
  • Message
  • Process
  • ThreadID
Tips: Use New-SPLogFile cmdlet to instruct SharePoint 2013 to start a new log file.

See the complete examples at Technet: Merge-SPLogFile Technet reference

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Database is up to date, but some sites are not completely upgraded

If you get the database status as "Database is up to date, but some sites are not completely upgraded" from "Review Database Status" page in Central Administration, it simple means: SharePoint Products Configuration wizard is unsuccessful in upgrading the specific database.
Database is up to date, but some sites are not completely upgraded
Solution:
  • Go to SharePoint Central Administration >> Upgrade and Migration >> Review database status >> Get the list of Databases that need upgrade.
  • Fix database upgrade status with below PowerShell cmdlet: Upgrade-SPContentDatabase
Fix database upgrade status with PowerShell cmdlet: Upgrade-SPContentDatabase
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set this variable value accordingly 
$DatabaseName = "content_database_name_here"

#Get the Database ID
$DatabaseID = (Get-SPContentDatabase -identity $DatabaseName).ID

#Update Content Database
Upgrade-SPContentDatabase -id $DatabaseID -Confirm:$false
Once the process completes, Go back to the "Manage Databases Upgrade Status"page in Central Admin and check the status, It should be "No action required."

Upgrade All content Databases:
Rather doing it one by one, lets upgrade all content databases in a single stretch.
$WebAppURL= "http://intranet.crescent.com"

#Get all content databases of the particular web application
$ContentDBColl = (Get-SPWebApplication -Identity $WebAppURL).ContentDatabases

foreach ($contentDB in $ContentDBColl)
{
 #Updade each content database
 Upgrade-SPContentDatabase -id $contentDB.Id -Confirm:$false
} 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, May 15, 2014

Find and Delete Unused Orphan Databases in SharePoint

Problem:
In a SharePoint 2013 pilot environment, Created several Web applications and service application for testing purpose. Some of those web applications are deleted without deleting their databases. After a while, The database server is filled up and we got to cleanup SQL Server by deleting unused SharePoint databases.

Solution:
Using SharePoint 2013 Central administration to find out the databases used by web applications.

Get Active SharePoint Content Databases:
Navigate to Central Admin > Application Management > Manage Content Databases page. You can select and see which content databases are used by web apps.

Get Active SharePoint Service Application Databases:
Similarly, Navigate to Central Administration > Manage Service Applications >> Select the  service application > Properties. This would show you what databases are used by the particular service application.

But, You got to repeat these steps manually for all web applications and service applications to find which ones you aren't using.

PowerShell Solution to find out Orphaned Databases:
Its tedious to compare SQL Server databases one by one, For each web application, for each service application, isn't it? Well, lets use PowerShell to find out active SharePoint databases.

Step 1: Export SharePoint Database Names to a Text file
Lets export SharePoint database names to a text file. Run:
Get-SPDatabase | Sort-Object Name | Select -ExpandProperty Name | Out-File "c:\SharepointDBs.txt"
delete orphaned database sharepoint 2013
This gets you all databases associated with your SharePoint farm!

Step 2: Export Database names from SQL Server
Login to SQL Server Management Studio, Run this Query:
SELECT [name] FROM master.dbo.sysdatabases WHERE dbid > 4 

Step 3: Compare Both files
If you have any text comparison utilities like BeyondCompare, your task is much easier. Otherwise, You can use PowerShell to compare these two files and get the difference.
#Get SharePoint Databases 
$SharePointDBs = Get-Content "C:\SharePointDBs.txt"
#Get SQL Server Databases 
$SQLDBs = Get-Content "C:\SQLDBs.txt"

#Compare 
Compare-Object -ReferenceObject $SharePointDBs -DifferenceObject $SQLDBs
Now, You got all unused databases. Open SQL Server Management Studio and identify each unused database from the above comparison and then delete any unused SharePoint database from SQL Server.
Important: Take backup before deleting any databases.

Database is actually deleted but still referenced in SharePoint?
What if the database is deleted and SharePoint still referencing it? Well, use this PowerShell script to find all deleted databases referenced:
#Find all deleted databases which are still referenced in SharePoint Farm
$OrphanDBs = Get-SPDatabase | Where {$_.Exists -eq $false}
$OrphanDBs

#Remove all Deleted database references in SharePoint
Get-SPDatabase | Where{$_.Exists -eq $false} | ForEach {$_.Delete()} 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Restore-SPSite : The operation that you are attempting to perform cannot be completed successfully

While trying to restore a site collection, with "Restore-SPSite" cmdlet in PowerShell, Got this error:

Restore-SPSite : The operation that you are attempting to perform cannot be completed successfully.  No content databases in the web application were available to store your site collection.  The existing content databases may have reached the maximum number of site collections, or be set to read-only, or be offline, or may already contain a copy of this site collection. Create another content database for the Web application and then try the operation again.
Restore-SPSite : The operation that you are attempting to perform cannot be completed successfully.

Root cause and solution:
  • If you try to backup - restore a site collection on SAME content database, you'll end-up with this error.
    Solution: Create a new content database and restore your backup to the specific content database.
    Restore-SPSite http://intranet.crescent.com/sites/sales -Path D:\Backup\sales.bak -DatabaseServer SP13SQL -DatabaseName SP13_Sales_Content 
  • If you are tyring to  overwrite an existing site collection, use: -force parameter with Restore-SPSite or the -overwrite parameter with stsadm -o restore
  • You backup a site collection  - Deleted the site collection - Trying to Restore the backup? Well, in SharePoint 2010 SP1 onwards, deleted site collections still lives in the content database to be able to recover. Use: Get-SPDeletedSite to get the GUIDs of deleted site collections and completely remove the site collection from the database using: Remove-SPDeletedSite -Identity "SiteGuid"
  • If you are trying to Delete and Re-Create a site collection, make sure its permanently deleted with "Remove-SPDeletedSite" cmdlet and Trigger “Gradual Site Delete” job from Central administration > Monitoring > Job definitions.


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, May 10, 2014

How to Change Favicon in SharePoint 2013

Favicon - short form for "Favourites Icon" adds branding to SharePoint 2013 sites. Its not only used for bookmark Favourites, but also in address bar, browser icon locations too. In case you want to change favicon in SharePoint 2013, here are the options.
Change Favicon in SharePoint 2013
SharePoint 2013 favicon location:
By default, SharePoint 2013 uses favicon located in path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\template\images" which is mapped as "/_layouts/15/images/favicon.ico", favicon size is: 16x16 pixels.
replace favicon sharepoint 2013
Add favicon to SharePoint 2013
To add favicon to SharePoint 2013 sites,
  1. Login to you SharePoint Foundation/Server WFE. Upload your custom favicon to 15 hive's images folder. If you have multiple WFEs, you must upload to all of your web front ends.
  2. Edit your master page (on publishing sites, edit your HTML master page) and locate the following chunk:
    <SharePoint:SPShortcutIcon runat="server" IconUrl="/_layouts/15/images/favicon.ico?rev=23" />
    In publishing sites which uses HTML master pages, its coded as:
    <!--SPM:<SharePoint:SPShortcutIcon runat="server" IconUrl="/_layouts/15/images/favicon.ico?rev=23"/>-->
  3. Just change the IconUrl value to point your custom icon. In my case, I've uploaded a custom icon "cloud.ico" and made the change as:
    <SharePoint:SPShortcutIcon runat="server" IconUrl="/_layouts/15/images/cloud.ico?rev=25"/> 
    Please note, I've increased the REV parameter from 23 to 25 in mitigate caching issue.
  4. Save, approve and publish your master page. Here is my custom favicon!
sharepoint master page favicon

How about changing favicon in SharePoint 2013 online?
If you are working in SharePoint online version or if you don't have server access to upload your custom icon to 15 hive, place the custom favicon in any library such as "Images", "Site Assets", etc and update master page as:
E.g.
<!--SPM:<SharePoint:SPShortcutIcon runat="server" IconUrl="http://sharepoint.crescent.com/sites/operations/PublishingImages/fav.ico"/>-->
Replace favicon in SharePoint 2013:
Although its fairly straightforward to replace the default Favicon.ico located in 15 hive with your custom favicon, its not a best practice! Always edit your master page to replace favicon in SharePoint 2013.

Favicon may not showing immediately?
Well, usually it takes few hits for the new icon to refresh. Try clearing your browser cache, IISReset if favicon is still not updated.

To change favicon for SharePoint 2007 and SharePoint 2010, refer my another article: Set favicon for MOSS 2007, SharePoint 2010 sites

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, May 8, 2014

No Apps are installed to open this type of link (grvopen) - Fix Sync Issue

Sync feature in SharePoint provides two way between SharePoint libraries and your local computer. Getting "No Apps are installed to open this type of link (grvopen)" error message on clicking "Sync" button in SharePoint 2013? In some cases SharePoint 2013 sync button not working?
sharepoint 2013 sync button not working
Solution:
SharePoint 2013 sync button requires Sync client (such as "SharePoint workspace")! You can also use  OneDrive for Business (formerly SkyDrive Pro) Sync client tool from: http://support.microsoft.com/kb/2903984

Its a Office 2013 application used to sync SharePoint libraries to your compute Pick the right tool for your language, and when prompted provide the product key supplied in the above link. Once installed, you should get sync functionality for your SharePoint sites.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, May 7, 2014

Change SharePoint 2013/2010 Site Logo Link to Root Site URL

By default, on clicking the SharePoint 2010 or SharePoint 2013 site logo - It takes us to the root of the current site or sub-site. But you may want to link logo to top level site.Well, to change this behavior you got to change the master page.
Important: Since this is a Master page change, You have to apply the updated master page to all site collections for the changes to take effect!

Set SharePoint 2010 logo link root site:
  • Open your Master page in SharePoint Designer 2010, Locate the below line:
<SharePoint:SPLinkButton runat="server" NavigateUrl="~site/" id="onetidProjectPropertyTitleGraphic">
  • Replace the ~site value with ~sitecollection .Save and close the master page (approve and publish, if required!) . This changes SharePoint 2010 logo link to root site collection.
    change sharepoint 2010 logo link URL
In SharePoint 2013 - Change site logo link URL:
  • Open your SharePoint 2013 site in SharePoint designer 2013, Edit the master page in "Advanced Edit Mode",
  • Locate the following code :
<SharePoint:SPSimpleSiteLink CssClass="ms-siteicon-a" runat="server" id="onetidProjectPropertyTitleGraphic" >
<SharePoint:SiteLogoImage CssClass="ms-siteicon-img" name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/15/images/siteIcon.png?rev=23" runat="server"/>
</SharePoint:SPSimpleSiteLink>
  • Replace the control <SharePoint:SPSimpleSiteLink> with <SharePoint:SPLinkButton> and add the "NavigateUrl="~sitecollection/" attribute to it.Here is the modified code:
<SharePoint:SPLinkButton NavigateUrl="~sitecollection/" CssClass="ms-siteicon-a" runat="server" id="onetidProjectPropertyTitleGraphic" >
<SharePoint:SiteLogoImage CssClass="ms-siteicon-img" name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/15/images/siteIcon.png?rev=23" runat="server"/>
</SharePoint:SPLinkButton >
This changes logo link URL pointing from current site to Root Site!
change sharepoint 2013 logo link



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Change Quick Launch Width in SharePoint 2013/2010/2007

When using lengthy titles in SharePoint 2013 quick launch bar, we may have to increase the width to fit the contents without wrapping to next line. Here are the nifty collection of CSS styles to change the width of left navigation in SharePoint.

SharePoint 2013 left navigation width:
<style type="text/css">
/*increase quick launch width */
#sideNavBox
{
  width:250px;
}

/*Middle Content */
#contentbox{
margin-left: 290px;
}

</style>

SharePoint 2010 increase quick launch width:
<style type="text/css">
/*sharepoint 2010 change left navigation width*/
 #s4-leftpanel
{
 width:180px;
}

/*Middle Content */
.s4-ca {
margin-left: 200px;
}

</style>

Change SharePoint 2007 quick launch width:
<style type="text/css">
/*sharepoint quick launch column width*/
.ms-quicklaunchouter
{
 width:150px!important;
 }
</style>
All of these SharePoint quick launch width changing CSS codes can be from Script Editor Web Part, SharePoint theme CSS file, Alternate CSS, placed in CEWP , Master page or Web Part page edited with SharePoint designer 2010 to increase quick launch width.

Here is the Before and after screens:
Before changing SharePoint 2013 left navigation width
sharepoint 2010 change width of quick launch
 After change width of left navigation:
 sharepoint 2013 increase quick launch width


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...