SharePoint listing all documents with versioning detail

Document library in SharePoint shows count of the documents only, but there are many minor and major versions for a document. In this blog post I am going to share how we can generate a report for a document library which have details for all major and minor versions of document version size and checkedIn comments.

You can check the size of document library using Storage Metrics but some time it does not show the exact size because its incremental only and always add the document version size to it, you need to reset it manually, check how to reset the SharePoint Storage Metrics size.

You can check the version details for any specific document by going to document version detail and check the version history with version detail, size, checked in comments and user who modified it.

SharePoint Document version history

Document library with large versions also slow down the performance of the document library, I am going to share a PowerShell script which will generate the versioning detail for a complete document library.

SharePoint Documents with versioning detail

The script will generate the report of a document library with all major and minor versions, it have a function named GetAllDocInventoryWithVerions which takes two parameters, the site URL and document library.

You can call the function output either in PowerShell gridview or in a CSV file. Run below cmdlet to execute the output in a gridview

To save the report in excel/csv, run the below command which will save the file at given location.

How to get CheckedIn comment

In above script, you need to get the checkedIn comment from the document version detail as Iisted in above script.

How to get Size for a specific version

Some time you want to know the size of a specific version, in above script I used the GetVersionsFromLabel method to get the size of a specific version. You can load any specific document using PowerShell and can get the version size.

Deleting document version using PowerShell

You can delete version directly from version history or using PowerShell script, powershell script will be helpful if you need to delete multiple versions.

$Ver here is the document version which I have looped in above script.

SharePoint Storage Metrics to Check size of a document Library

SharePoint storage gives us a very useful report to understand the size of a site, sub site, list and library. To view the Storage Metrics report you have to follow simple steps

Go to Site Collection Settings –> Site Collection Administration –> Storage Metrics

SharePoint Online Storage Metrics

You can drill down the document library or sub site to view further detail, this can show you the size of any particular document including the size of its versions. Storage matrix is available in both SharePoint Online and SharePoint On-Premise versions.

Why Storage Matrix value not changing

We can see the size of a document and we can also check its versions sizes by checking the version history but how to check the actual size of a document library. Recently I faced similar issue where the response of a specific document library got really slow, customer reported one specific document which getting too slow, the size of document was around 33 MB, then I checked the versioning detail which was terrible, they have over 13 major versions and each major version having 300 to 400 minor versions. It was a SharePoint 2010 document library and Storage Matrix shown over 26 GB size for a single document, check the below screen.

SharePoint 2010 Storage Metrics

So, we suggested to delete older major and minor versions to reset the document size. We deleted the document first major versions and all the minor versions under them. When we rechecked the Storage Matrics value, it still showing the same result, but document library performance was not bit better.

When user adds/deletes document to a versioned library SharePoint is updating TotalSize field in Storage Metrics table to add/deduct the document size from the existing value.

It appears that the usage of web folders to add/delete files is only adding size value to TotalSize field in Storage Metrics and not deducting size value for delete. I also have queried the specific document in SQL Server database to verify the size, but database also showing the same result

SQL Server Storage Metrics

((28216479333/1024)/1024) = 26909.33 MB

Solution: Reset or recalculate the Storage Metrics output

If you are getting this issue on SharePoint 2013 or SharePoint 2016 farm, you need to run the following PowerShell command to recalculate metrics.

If you are using SharePoint 2010 then use the below PowerShell cmdlet to recalculate Storage Matrix

* SP1 is required for SharePoint 2013 to run above cmdlet.

Show or hide SharePoint list and libraries

SharePoint lists and libraries are visible to all users and there are various ways to hide them. Admin can break inheritance for the list/libraries and set permissions for a specific group of users, this will hide the list from all users except that specific group and list content will only be available if user have the permissions. But sometime we can have few list or libraries where we added some configuration information and do not want user to directly access that but the list items or documents can be shown to them through different web parts, in this scenario the break inheritance will not work and we might have to use either PowerShell or SharePoint designer (or stsadm for older versions). In this blog post I am going to share the PowerShell script to show/hide the list and libraries in SharePoint online and SharePoint on-premise and also how we can achieve this using SharePoint Designer. You can download the PowerShell script for SharePoint Online and on-premise from TechNet.

SharePoint Hide show list and libraries

Hide list and libraries in SharePoint Online

Use the below PowerShell script to show or hide the list and library from the users for SharePoint Online (Office 365). I have written a simple function.

You have to call the function ShowHideList which require three parameters.

You can easily show/hide a SharePoint List or library using above function in SharePoint Online. Download the above PowerShell script from GitHub.

Hide list and libraries in SharePoint On-premise

Use the below PowerShell script to show or hide the list and library from the users for SharePoint On-Premise (SharePoint 2010, SharePoint 2013, SharePoint 2016, SharePoint Foundation). Just like the script written in above section, I have written a PowerShell script having the same function name but for on-premise environment.

You have to call the function ShowHideList which require three parameters.

Download the above PowerShell script from GitHub.

Hide list or Library using SharePoint Designer

SharePoint Designer is a very useful tool when you need to do some customizations, if you do not have development expertise to execute any PowerShell Script then you can easily do it using SharePoint Designer.

Open the site in SharePoint designer and click on Lists and Libraries from left panel. This will show all the list and libraries in current particular site.

SharePoint Hide show list and libraries - SPD

Click on the list or library which you want to show or hide from the browser or view site content. In the settings section, click on the “Hide from Browser” under General. Save the changes and refresh site in browser, the list/library is now hidden from all users.

SharePoint Hide show list and libraries - SPD

Note: The above methods will only hide the list/library for browser view but user still can access it using URLs.

Enable versioning in SharePoint Document library

Versioning is very important for documents, it provides a way to keep track of the changes and who made to those changes.  Each time you save the document, it saved with a new version, versions can be minor or major.

Follow the below steps to enable versioning in document library

  1. Go to SharePoint Document library settings
  2. Click on Versioning Settings
  3. You can see the different option to enable versioning.

SharePoint Document Library Version setting

If you have selected the major versions then every time you do any modification in the document, it will be saved as major version, and if you selected the option showing major and minor version then it will save draft documents as minor version. You can also enable content approval, which will assign a task to someone to review the document and only published (or approved) documents will be visible to end users.

Restore an older version

You can restore an old version if required, the steps are very simple. Click on the document version history, it will list all the versioning detail containing major and minor versions. Click on the arrow to which will show the option to restore selected version. The version will be saved as a new version of the document.

SharePoint restore older version

Follow to similar steps to disable versioning for a document library.

Integrating Yammer with SharePoint

Yammer has been moved under Office 365 and there are different ways to integrate it in SharePoint Online or SharePoint On-Premise. Below are different ways to integrate yammer in SharePoint Online and on-premise

  • We can use the remote provisioning pattern to create Yammer groups or Topic feeds to facilitate conversations when you create new SharePoint sites.
  • We can use the out-of-the-box embed functionality to quickly and easily integrate Yammer with SharePoint. Embed a Yammer feed(my favorite) into a SharePoint site:
    • Group feed: Group feed shows the latest conversations for a specific Yammer group.
    • My Feed / User Feed: As the name shows that these are user specific feeds and all items relevant to current user (my feed) or specific user (User Feed). All the user specific feed updates will be shown
    • Topic Feed: It’s a feed which is tagged on a specific topic
  • We can use the OpenGraph API and/or Yammer REST API with Yammer SDKs to create customized integration functionality.
  • Yammer app: Yammer app for SharePoint has been deprecated, and Yammer embed is the alternate solution to integrate in SharePoint.

If you having different credentials for Yammer and SharePoint (may be in case of SharePoint on-premise), for single-sing-on you need to do little development using Yammer SDK. Develop a custom component using Yammer SDK which can save user token for single-sign-on. Check below links for more detail.

Useful Links:

Yammer integration in the SharePoint add-in model

Use Yammer Embed instead of the Yammer app for SharePoint 2013 and SharePoint Online

Using JSLink as an alternative for Calculated columns

JSLink came with SharePoint 2013 but it was not used that much at the time because people are much more comfortable with farm/sandbox baased solutions and playing with XSLT was fun. But with rise in usage of SharePoint Online (office 365) it become one of the necessity one should know.

JSLink is pretty smart or we can call it modern way to render list views, item and fields using JavaScript, HTML and CSS, no need to learn XSLT. Previously if we need to do some customization in list view web part then we have write a complex xslt which is not easy for everyone. And now with JSLink, you only need to have understanding of how to javascript works.

Recently you heard that Microsoft has disabled HTML markup from calculated columns in SharePoint Online. In SharePoint 2016, this functionality is disabled on web applications which are provisioned after installation of July 2017 PU, use below is the Powershell cmdlets  to enable it on SharePoint 2016 for a web application.

But do we still need to use calculated columns? NO, we can use JSLink to render list items using client side and can define the rendering of a list view web party or for any specific field, which is quite fun.

In this blog post, I am going to share to share a real-life example where we have used calculated columns to render specific html markup for a list view which stopped working after recent change in SharePoint online, initially we thought that this will be time taking job as we need to work on list view xslt but JSLink did the job and made life much easier than before. Below is the screenshot where you can see html markup showing in html markup instead of the images which we tried to show.

List View Calculated Columns

In above picture, you can see the HTML markup, each of the calculated column having several conditions like below:

The previous look of the same list view was showing check boxes as shown below:

List View JSLink

I have blurred some of the content due to some sensitive information, in the above picture you can see the difference, so I have to achieve the similar out using JSLink, below is the JavaScript I used:

In above script I have used specific list fields to update, similary you can use the complete fieldCtx.Templates.Item to render all list items instead of fieldCtx.Templates.Fields.

Copy the script in a .js file and save it in Style Library or asset library and go to the list view page. To edit the page, click on the gear icon and click Edit page.

SharePoint Edit Page

Now go to the list view web part properties.

SharedPoint Edit Web part

Expand the miscellaneous tab and copy the file URL under JSLink.

SharePoint JSLink

Make sure to enter the correct file path, if you have saved it in current site then use ~site (Click here to get file path URL in SharePoint). It might not work if you have given full path. Also add some alert to make sure file is referenced properly.

The above is working on SharePoint 2013, SharePoint 2016 and SharePoint online. I will be sharing more samples on JSLink for list view also specific fields.

Missing web part and features in office 365

Many office 365 users face the issue that the root SharePoint site not showing all the web parts and features but these features and web parts are available in other site collections of the same tenant except the root site like http://mstalk.sharepoint.com.

This happen mostly when you setup a new tenant and try to add web parts on the pages and come to know that some most common web parts like Content Edit or script editor missing.

Office 365 missing web parts

Do not try to activate different features, this is because custom scripts are disabled on root site collection for security reasons and due to that Script Editor, Content Editor web part and many other web parts or features are not available where user can add custom scripts. Follow the below steps to active the custom script.

You need to be have the global admin permissions for SharePoint on your tenant. Go to SharePoint admin center (URL will be: https://tenantName-admin.sharepoint.com) and click on settings.

Office 365 SharePoint Admin Panel

Scroll down the settings page and you will the Custom Script section. Allow both options to enable scripting on the site collection as shown in below picture, this will allow user to have missing web parts and features on all site collections.

Office 365 SharePoint Custom Script

If you check the instructions, its mentioned that it will take 24 hours to enable custom script on your tenant which include all site collections and OneDrive.

But who have that much time and in most of the cases no one wants to enable it for all site collections.  So, if you can use below PowerShell script to enable custom script on single site collection with immediate effect.

Set-SPOsite <SiteURL> -DenyAddAndCustomizePages 0

The PowerShell script take few seconds to complete the execution. Once the script is completed, you can see the all the missing web parts are visible. Now you can also compare the first screenshot and below one for the different. I will be sharing complete list of missing features and web parts in next section.

Office 365 SharePoint Add Web part

Site features not available

Below is the list of site features which are not available when custom script is set to prevent from users.

  • Save Site as Template
  • Save document library as template
  • Solution Gallery
  • Theme Gallery
  • Help Settings
  • HTML Field Security
  • Sandbox solutions
  • SharePoint Designer(Create Form and Custom Action will no longer work.)

Blocked File Types:

  • .asmx
  • .ascx
  • .aspx
  • .htc
  • .jar
  • .master
  • .swf
  • .xap
  • .xsf

Web parts not available

Below is the list of web parts which are not available when custom script is not allowed:

Web part category Web part
Business Data Business Data Actions

Business Data Item

Business Data Item Builder

Business Data List

Business Data Related List

Excel Web Access

Indicator Details

Status List

Visio Web Access

Community About This Community

Join

My Membership

Tools

What’s Happening

Content Rollup Categories

Project Summary

Relevant Documents

RSS Viewer

Site Aggregator

Sites in Category

Term Property

Timeline

WSRP Viewer

XML Viewer

Document Sets Document Set Contents

Document Set Properties

Forms HTML Form Web Part
Media and Content Content Editor

Script Editor

Silverlight Web Part

Search Refinement

Search Box

Search Navigation

Search Results

Search-Driven Content Catalog-Item Reuse
Social Collaboration Contact Details

Note Board

Organization Browser

Site Feed

Tag Cloud

User Tasks

Also visit Allow or prevent custom script for more details.

Hide fields from SharePoint List Forms

Some time we got the requirement to hide few fields from a SharePoint list form but do not want to remove them from the list, some list columns used in different content types and we cannot hide them through column properties.

Most of the time we need this in task forms to hide or disable few fields from users and also on Document Sets where user do not want to have Document set metadata fields on document edit form.

In this article, I will be sharing a jQuery script which you can use to hide fields from Display and edit forms (even you can use it in add form).

The list form generates fields markup and assign ID dynamically which you cannot get directly by Element ID or Element Name properties. You need to get it using jQuery select attributes like Attribute Contains Selector [name*=”value”], or Attribute Contains Word Selector [name~=”value”] or Attribute Ends With Selector [name$=”value”].

I am taking example of a list form of a task form to hide few fields from display form and also from edit for using jQuery and CSS.

Hiding fields on Display Form

Go to task list and click on a task list item which will show you the task display form with item detail. Below is the picture of Task display form, I am going to hide the “Start Date”, “See also”, “%Complete” and “Related Items” fields from the display using custom CSS and jQuery.

SharePoint View form

Click on the Gear icon on top right and click Edit to edit this page.

SharePoint Edit Page

Click on Add a web part button and add a script editor web part to the page.

SharePoint Add Script Editor Web Part

Custom JavaScript to hide fields from page

Click EDIT SNIPPET link to add the custom script, add below script in script editor under <script> tag. You can also create a function and execute the function at end. (download script file from GitHub)

Css to hide See Aslo

Add below css on the script editor under style tag.

Save the changes on the page, it will take you to the all item page of list. Reopen the list display form by clicking on list item and you will see the difference as shown in below image.

SharePoint View form after hiding fields

Hiding Fields from Edit Form

The edit form having different form structure as it has form controls like input, drop down and buttons. In below form, you can see few fields which I am going to hide using JavaScript.

SharePoint Edit Form

Follow the similar steps as define above to add the script editor web part, below is JavaScript which can be used to hide the form fields. (download script file from GitHub)

If you check the script, it going to hide “Start Date”, “% Complete”, “Predecessors”, “Task Outcome“ and “Content Type” field from the form. You can see the hidden fields in below form.

SharePoint Edit form after hiding fields

 Hiding fields in Document Sets

This is also one of the requirements for most of customers that document should show the metadata fields of document set but hide them on the document Edit form, use the above mentioned script to hide the fields document edit form in a document set.

Get SharePoint List Inventory using PowerShell

PowerShell scripts are very useful to generate some amazing reports, recently I have written a PowerShell script which retrieves all lists and libraries for a SharePoint site collection under all sub sites with item count and versioning enabled.

This is a report which can be very useful when you are going to the delta/cutover migration and you can get the details for list and libraries recently modified and also item count.

Use this report to compare list count including item count in each list for different sites (useful in migrations).

You can download the script directly from GitHub repository.

Include the reference SharePoint PowerShell.

if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
}

I am going to create a function name “GetListInventory” which will take one site Url as parameter.

function GetListInventory($siteUrl)
{
$webApp = Get-SPWebApplication $siteUrl

$SiteDetail = @();

Foreach ($web in $webApp | Get-SPSite -Limit All | Get-SPWeb -Limit All)
{
Write-host “Processing site $web.Name…”

foreach($list in $web.lists)
{
$row = new-object PSObject
Add-member -inputObject $row -memberType NoteProperty -Name “Site Name” -value $web.Name
Add-member -inputObject $row -memberType NoteProperty -Name “URL” -value $web.Url
Add-member -inputObject $row -memberType NoteProperty -Name “List Title” -value $List.Title
Add-member -inputObject $row -memberType NoteProperty -Name “List Item Count” -value $list.Items.Count
Add-member -inputObject $row -memberType NoteProperty -Name “Last Modified Date” -value $List.LastItemModifiedDate
if ($list.EnableVersioning -eq $TRUE)
{
Add-member -inputObject $row -memberType NoteProperty -Name “Versioning” -value “Yes”
}else
{
Add-member -inputObject $row -memberType NoteProperty -Name “Versioning” -value “No”

}
$SiteDetail += $row;
}
}
$SiteDetail
}

I have used list.Items.Count property instead of Lites.ItemCount.

Difference between List.items.Count and List.ItemCount

Now you have compiled the above script, call the function to generate the list inventory. You can either print output on Out-GridView or in a CSV file using Out-File.

GetListInventory “http://SP2016Farm” | Out-GridView

SharePoint List Inventory

In above report, you can see the Site title, site URL, List name, no. of items, Last Modified Date and versioning which will be yes if enabled

But it will be very useful if you copy the content from above report into excel or generate a csv report will using Out-file:

GetListInventory “http://SP2016Farm” |  Out-File “E:\Reports\ListInventory.csv”

SharePoint List Inventory Out-File

Using excel you  can apply different sorting orders and filters in excel like to get the list with maximum no. of items, latest or lest modified list, lists with versioning enabled or for any specific site. These types of filters are quite easy in excel. Instead of applying these filters in PowerShell, generate lists inventory like this and then perform different actions on it.

Important: I have tested this script in SharePoint 2010, SharePoint 2013 and SharePoint 2016.

Changing site logo for all sub sites in a Site collection for SharePoint Online (Office 365)

In my previous article, I shared details for changing site logo for a site collection and its sub sites using PowerShell, but that was only for on-premise environment. PowerShell script for SharePoint Online is different from on-premise where we refer SharePoint client dlls, make sure you should have installed SharePoint Online Management Shell, if not then you can download it from this link.

I have update the script at technet gellery for changing site logo for both SharePoint On-Premise as well as for SharePoint Online, you can download it from this link.

MsTechtalk Technet gallery

Below is the PowerShell script which update the site logo for all sub sites under a site collection, it will ask you for site URL, user name and password.

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint.Client”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint.Client.Runtime”)

$siteUrl = Read-Host -Prompt “Enter site collection URL (https://mstechalk.sharepoint.com)” #you can also set the site URL
$userToLogin = Read-Host -Prompt “Enter Username” #you can also set the user name, make sure it should be global admin
$password = Read-Host -Prompt “Enter Password” -AsSecureString
$sitelogoURL = “/SiteAssets/newSitelogo.gif” #change the site logo
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userToLogin, $password)

$clientContext.Credentials = $credentials

$web = $clientContext.get_web()
$webs = $clientContext.Web.Webs;
$clientContext.Load($webs)
$clientContext.Load($web)

$clientContext.ExecuteQuery()

function updateSubSites($subWeb) {
$subsites = $subWeb.Webs;
$clientContext.Load($subsites)
$clientContext.ExecuteQuery()
foreach ($subSite in $subsites) {
updateSiteLogo($subWeb)
updateSubSites($subSite)
}
}

function updateSiteLogo($subWeb) {
$subWeb.SiteLogoUrl = $sitelogoURL
$subWeb.Update();
$clientContext.ExecuteQuery()

Write-Host “Updated logo for ” $subWeb.Title ” , site url:” $subWeb.Url
}

updateSiteLogo($web)

foreach ($subWeb in $webs)
{
write-host “inside bottom foreach”
updateSiteLogo($subWeb)
updateSubSites($subWeb)
}

You might get below exception if the user is not global admin, so make sure you have credentials for global admin.

Exception calling “ExecuteQuery” with “0” argument(s): “The Login server cannot issue the requested compact encrypted ticket because a Data Encryption Key (DEK) has not been uploaded to the site.”

At line:19 char:1

+ $clientContext.ExecuteQuery()

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : IdcrlException