Tag Archives: SharePoint 2013

How to: get a number of lists and lists items for SharePoint site collection

The fastest way to do it is to use following PS script:

Add-PSSnapin Microsoft.Sharepoint.Powershell

$ListsInfo = @{}

$TotalItems = 0

$SiteCollection = Get-SPSite "http://sitecollection.domain.com/"

ForEach ($Site in $SiteCollection.AllWebs)

{

ForEach ($List in $Site.Lists)

{

$ListsInfo.Add($Site.Url + " - " + $List.Title, $List.ItemCount)

$TotalItems += $List.ItemCount

}

}

$ListsInfo.GetEnumerator() | sort name | Format-Table -Autosize

Write-Host "Total number of Lists: " $ListsInfo.Count

Write-Host "Total number of ListItems: " $TotalItems

It will count all the lists and number items inside of these lists, plus output total lists number and total items number in all lists for site collection URL of which you specify in 4th line of this script. This script works both for SharePoint 2010 and 2013.

If you are on look out for script to generate some list items for testing purposes you may find exactly what you need in Cameron Dwyer’s blog, in the following post “SharePoint PowerShell How To: Create SharePoint List Items (in Root and in Folders) for Load/Performance Testing.”

How to export / and import SharePoint 2013 sites, lists, or libraries with PowerShell

For copying individual items across your SharePoint 2013 environments or making single item backups of  sites, lists, or libraries you may employ following PowerShell commandlets: Export-SPWeb and Import-SPWeb.

Here is a basic example of performing library export and further import using those cmdlets. First, export:

Export-SPWeb -Identity http://sitename.domainname.com -ItemUrl /Library_Name -path "c:\Library_Name_Backup.cmp"

The only thing which may cause some difficulties is how to correctly specify Identity and URL parameters, as if you are going to look at the URL of SharePoint library when it is opened in browser and try to use it – it won’t work out. Usually URL of a library accessed in browser looks similar to this:

http://yoursite.yourdomain.com/_layouts/15/start.aspx#/Your_Library_Name/Forms/AllItems.aspx

You have to take parts highlighted in bold for Export-SPWeb as a values for Identity and ItemUrl parameters including slash symbol in front of library name, otherwise it won’t work. E.g. if you omit slash in the beginning of URL parameter value Export-SPWeb will throw following (not quite self explanatory) error at you:

Export-SPWeb : <nativehr>0x80070057</nativehr><nativestack></nativestack> At line:1 char:1

So type things carefully 🙂

Next is import:

Import-SPWeb http://yoursite.yourdomain.com -Path c:\Library_Name_Backup.cmp -UpdateVersions Overwrite

Use of this 2 cmdlets will help you to create item level backups for sites, lists and libraries in SharePoint 2013. By the way for those who wondering what CMP file extension stands for – this is abbreviation for “Content Migration Package”.

And if you want to run these commands from regular PS session without starting SharePoint Management Shell be sure to load SP PS snapin using script below:

K2 for SharePoint and SharePoint 2013 Distributed Cache Service

Recently I heard about situation when there were issues with installing K2 for SharePoint application related with missing Distributed Cache Service on SP server (there were related errors in SP logs and errors when adding K2 app in SP). This forced me to learn a bit about this Distributed Cache Service technology.

As with many of utility services or infrastructure things which supposed to do their job silently and transparently you may appreciate their usefulness and complexity only when things went wrong with them. Once such stuff broken you first realize how useful it was and what doesn’t work without it, and next when you trying to fix the stuff you start learning about complexities of this stuff 🙂

Short definition: SP Distributed Cache is a service that provides caching functionality which runs on an application server in SharePoint Server 2013. All microblog features in SharePoint Server 2013 depend on the Distributed Cache service.

The way Distributed Cache being leveraged by SP and solutions based on SP definitely deserves separate post along with clarifying the question when it is really required and what doesn’t work without it.

So far I just note that this service should be in place and properly configured for SP 2013 farms with multiple web front ends (on all WFEs).

Most useful links which I found researching this are (exactly in this order):

AppFabric Caching and SharePoint: Concepts and Examples (Part 1)

AppFabric Caching (and SharePoint): Configuration and Deployment (Part 2)

Plan for feeds and the Distributed Cache service in SharePoint Server 2013

First 2 posts by Josh Gavant [MSFT] are definitely must read if you want to understand how caching works in SP.

UPDATE: I also posted a question on serverfault.com back in December 2014 to get some comment on which SP features necessitate/require Distributed Cache Service, and only recently some answer come up. Main take away from this answer is that “Overview of microblog features, feeds, and the Distributed Cache service in SharePoint Server 2013” article on TechNet contains “Different caches that depend on the Distributed Cache service” table which lists what types of cache in SP depend on  Distributed Cache Service.

Also: The Distributed Cache service provides in-memory caching services and does not have a dependency on databases for several features in SharePoint Server 2013. Some of the features that use the Distributed Cache service include:

\n\n

    \n

  • Newsfeeds
  • \n

  • Authentication
  • \n

  • OneNote client access
  • \n

  • Security Trimming
  • \n

  • Page load performance

When the service is enabled, these features use the Distributed Cache for quick data retrieval. Blob Cache and Output Cache do not use a distributed caching service since these types of cache exist on each Web Front End server in the farm.

The microblog features and feeds rely on the Distributed Cache to store data for very fast retrieval across all entities.Following activities depend upon on news feed.

\n\n

    \n

  • Microblog activities This includes posts, replies, likes, mentions, or tagging an item.
  • \n

  • Following activities This includes when a user follows people, documents, sites, or tags.
  • \n

  • User profile activities This includes birthday, job title change, anniversary, updates made to Ask Me About, creating a new blog post, or posting on a Community Site.
  • \n

  • Document activities This includes when a document is edited or a document is shared.

\nThanks to Waqas Sarwar MCSE for his answer.