SharePoint24x7 It's all about SharePoint.


Tips n Tricks – Navigating through SharePoint ULS logs using PowerShell

Posted by Joy

When troubleshooting SharePoint farms, ULS logs play a vital role. ULS logs are the entry point for both Administrator and Developers when they start investigating an issue in a SharePoint farm.

Usually ULS logs are created in the following directory in SharePoint servers:

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\LOGS

ULS log files are easier to locate among other log files since their file name start with the server name and followed by a the timestamp.

ULS Logs directory

ULS logs contains very detailed information compared to Windows Event Logs. Following is a sample of a ULS log file:

ULS Logs

One of the big challenges/ pain point with regard to ULS logs are reading/ navigating through them. Since they are very detailed, going through them is really challenging. When we open a ULS log file, by default it opens in Notepad and it is really difficult to navigate through them.

Most of us try using lot of 3rd party tools for navigating through ULS logs without knowing that PowerShell also provide a powerful option for us to navigate through ULS logs.

Open SharePoint 2013 Management Shell and issue the following PowerShell command:

Get-SPLogEvent | Out-GridView

PowerShell command

This command will open up a new windows with a Grid View view of ULS log file. This allows us to navigate and filter ULS log entries easily compared to Notepad.

ULS Log Grid View

ULS Log Grid View Filtering


Tips n Tricks – Enabling Geolocation field in SharePoint 2013

Posted by Joy

SharePoint 2013 introduced a new site column with a new data type called Geolocation which enables us to store Latitude and Longitude information. This enables us to use Bing Maps API and visualize information in a map within SharePoint.

When I started looking at using this new geolocation site column all sources directed me to standard exercise of adding a site column into a list using list settings page.

It turns out to be really frustrating that I couldn’t see any geolocation site column to add.

Add site column

Finally I found a PowerShell commandlet which adds a geolocation to a list and I managed to add a geolocation to my list. Following PowerShell commandlets adds a geolocation site column to a list:

$web = Get-SPWeb ""

$list = $web.Lists["Contacts"]

$list.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Location'/>", $true, [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)


Tips n Tricks – tweaking the Windows PowerShell Profile

Posted by Joy

Windows PowerShell is the primary scripting tool available for SharePoint Administrators and Developers. Scripting was something most of the developers wanted to stay away from. But now it’s time for all the developers to master Windows PowerShell scripting since it is the core scripting platform from Microsoft. Just like Shell Scripts in Unix and Linux platforms, Windows PowerShell is the key to scripting within Microsoft technology stack.

Let’s get started with Windows PowerShell. Smile

When it comes to writing PowerShell scripts for SharePoint, we have no of tool options:

  • Windows PowerShell console window
  • Windows PowerShell Integrated Scripting Environment (ISE)
  • SharePoint 2013 Management Shell

Most of us who are into SharePoint, always prefer using SharePoint 2013 Management Shell since it loads all the SharePoint cmdlets by loading Microsoft.SharePoint.PowerShell.dll into the scripting environment.

If we are going to use Windows PowerShell console window or Windows PowerShell ISE, we will have to explicitly load the Microsoft.SharePoint.PowerShell.dll by executing following PowerShell command in order to being able to use SharePoint cmdlets.

Add-PSSnapin Microsoft.SharePoint.PowerShell

If you are writing very large, interactive scripts very often, it is probably easier to use the Windows PowerShell ISE, rather than the PowerShell console window or the SharePoint 2013 Management Shell because this provides a better editing and debugging environment. However, downside of using the PowerShell ISE is you will have to load the Microsoft.SharePoint.
PowerShell snap-in into the ISE as well every time you open it. It will be done by using exactly the same script shown above.

If you find yourself using the PowerShell ISE a lot, you can be smart to save your effort and time by adding the SharePoint snap-in automatically when the PowerShell ISE starts. You can do this by tweaking the Windows PowerShell profile.

The Windows PowerShell profile is a Windows PowerShell script file that runs every time you start Windows PowerShell. It has a .ps1 extension like any other normal Windows PowerShell script file. We can put any valid Windows PowerShell cmdlet in it so that they get executed every time we start Windows PowerShell. This is very similar to using Environment variables concept to configure startup options back in Windows Command Prompt tool. The only way in which the PowerShell profile file differs from a normal PowerShell script file is in its file name and file location.

If you are planning to use the PowerShell profile to configure startup cmdlets, as the first step, we need to figure out whether a PowerShell profile already exists on the server. We can figure out whether a PowerShell profile already exists by issuing following command:

Test-Path $profile

Check for profile

Check for profile

If the PowerShell profile already exists, above command will return “True”. If it doesn’t exist, it will return

If it returns either True or False, (i.e: whether the PowerShell profile exists or not), if you want to find out the default location of the PowerShell profile, you can run the following command:


Location of the profile

Location of the profile

And then, we can use Windows Explorer to browse to the path returned to make required modifications into the PowerShell profile script file.

If there is no file in that location. it means PowerShell profile does not exists and we need to create a new profile.

Use following command to create a new PowerShell profile if one doesn’t already exist.

New-Item -path $profile -type file

In case, if you receive an error response similar to one shown below as a result of executing the above command, make sure you have the correct folder path already in placed for the command to go and create the script file.

Error creating the profile

Error creating the profile

If the folder path exists and if it does create the PowerShell profile file successfully, you should receive the following response.

Creating the profile

Creating the profile

Use Windows Explorer to navigate to the file location and open the profile script file using any text editor such as Notepad.

Locating the profile

Locating the profile

Enter the following PowerShell command in the file, Save the script file and close the text editor.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"

Tweaking the profile

Tweaking the profile

Now you are all set to use Windows PowerShell ISE and Windows PowerShell console window to write SharePoint scripts. Now when you open either Windows PowerShell ISE or Windows PowerShell console window, it reads the PowerShell profile script file and load SharePoint PowerShell snap-in automatically.

Happy scripting…!!! Smile


Tips n Tricks – SharePoint 2013 support for Windows Server 2012 R2

Posted by Joy

I'm blogging this quickly to make sure that you guys won't waste time like me trying to install SharePoint 2013 on a Windows Server 2012 R2 machine.

I was trying to setup a new virtual machine and as usual I went and downloaded all the latest software through my MSDN Subscription. I installed and configured Windows Server 2012 R2 and installed Active Directory and SQL Server as usual and when it comes to installing SharePoint 2013, I lost my patience. I tried installing Prerequisites installer and it just gave me the following error:

Application Server Role, Web Server (IIS) Role: configuration error

It didn't allow me to proceed and I went searching Bing and Google and found number of posts suggesting me to try following:

None of the above workarounds didn't make my life better and it just gave me the same error and stopped Prerequisites installer giving me the above error.

Finally, I decided to do another search and here is what I found from Bill Baer's blog - :


Currently, Microsoft SharePoint Server 2013 is not supported for installation on computers running the Windows Server 2012 R2 operating system.   Installing SharePoint Server 2013 on a computer that is running Windows Server 2012 R2 could lead to unexpected behavior, therefore, Microsoft does not support SharePoint Server 2013 in Windows Server 2012 R2.

SharePoint Server 2013 with Service Pack 1 and SharePoint Foundation 2013 with Service Pack 1 will offer support for Windows Server 2012 R2. The release date for Service Pack 1 for SharePoint Server 2013 and SharePoint Foundation 2013 is to be determined. This article will be updated as more information becomes available.

I found the answer to my problem and it doesn't support Windows Server 2012 R2. I'm going to start from the scratch with Windows Server 2012 and I believe Bill Bear's blog will give you more information about this issue.


Enabling Developer Dashboard in SharePoint 2010

Posted by Joy

ASP.NET provides Call Stack and Tracing as wonderful features which helps developers on investigating what is going on page rendering behind the scene. SharePoint being a product which provides bunch of features OOTB which we can use to setup a portal very easily, it hides most of these information.

Back in MOSS 2007, we had to scratch our head thinking where to start our investigation when we get an error in the browser, because that error was not descriptive enough for us to start the investigation.

In SharePoint 2010, we have a nice feature – Developer Dashboard which helps developers to be comfortable when they see an error in the browser.

Enabling Developer Dashboard

Developer Dashboard is a feature targeted for developers (administrators as well) and hence it is disabled by default. We need to enable it using one of the method mentioned below:

  • PowerShell
  • SharePoint Object Model

We still can use STSADM with SharePoint 2010 for administering SharePoint. However, STSADM is more likely to disappear in the next release. Though we can use following STSADM command to enable Developer Dashboard, I strongly recommend to get familiar with PowerShell, if you are not already.

  1. Go to the command prompt and make sure to either set the path to the location of STSADM.EXE or navigate to the bin directory in SharePoint root in your command prompt.
  2. Issue the following command in the command prompt:STSADM -o setproperty -pn developer-dashboard -pv ondemand

The above command will enable the Developer Dashboard in On Demand mode.

  1. Go to Start –> All Programs –> Microsoft SharePoint 2010 Products –> SharePoint 2010 Management Shell
  2. Issue the following command in the management shell:$devdash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;
    $devdash.DisplayLevel = ‘OnDemand’;
    $devdash.TraceEnabled = $true;

The above command will enable the Developer Dashboard in On Demand mode.

SharePoint Object Model
  1. Create a Console Application, Windows Application or Web Site and add a reference to the Microsoft.SharePoint.dll assembly.
  2. Add using Microsoft.SharePoint.Administration namespace reference at the top of the code (C#) file.
  3. Add the following code into your code (C#) file to enable Developer Dashboard:SPWebService svc = SPContext.Current.Site.WebApplication.WebService;
    svc.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.OnDemand;

The above command will enable the Developer Dashboard in On Demand mode.

I have used On Demand as the setting for Display Level of the Developer Dashboard and following are the other options we can specify:

  1. On – Enable the Developer Dashboard all the times
  2. Off – Disable the Developer Dashboard
  3. OnDemand – Enable the Developer Dashboard but will be displayed on demand.

When you enable Developer Dashboard in On Demand mode, following icon will be displayed next to your login name.


On click of the Developer Dashboard icon, page will be reloaded and Developer Dashboard will be displayed at the bottom of the page as shown below:


If you have also used TraceEnabled = $true switch with PowerShell, then you will see a link says “Show or hide additional tracing information …” at the end of the Developer Dashboard which allows you to show/ hide ASP.NET Tracing information as shown below:


Isn’t this a awesome feature for you to get started your investigation exercise? Have a closer look at what Developer Dashboard offers you and it will help you in numbers of ways.