Powershell to create calendar in SharePoint with categorized overlays

Creating calendars in SharePoint 2010, changing default categories and then creating view and overlay for each category can take a lot of clicks. To save time and effort I created a powershell script which can be used as follows

& ‘.\Calendar Overlay.ps1′ -webUrl {SITEURL} -listName “{LISTNAME}” -categories “{CommaSeparatedCategories}”

It takes three command line parameters which are

-webUrl – The site url where you want to create the calendar

-listName – The name of calendar list

-categories – Comma separated values for categories

For example if you would like to create a calendar named Yearly events on http://myspsite/marketing with road show, marketing boot camp 1 and digital campaign 1. You can pass in the following arguments

& ‘.\Calendar Overlay.ps1′ -webUrl http://myspsite/marketing -listName “Yearly Events” -categories “Road show, Marketing Boot camp 1, Digital Campaign 1″

The resulting calendar would look like

Calendar overlays created with Powershell

Source for the script is as follows:

###############################################################################
# Creating Calendar overlays in SharePoint 2010 using Powershell
# Version          : 1.0
# Url              : http://khurrampunjwani.wordpress.com
# Creator          : Khurram Punjwani, http://twitter.com/khurrampunjwani
###############################################################################

param (
    [string]$webUrl = $(throw "-webUrl is required."),
	[string]$listName = $(throw "-listName is required."),
    [string]$categories = $(throw "-categories is required.")
 )

[array]$categoriesArray = $categories -split ","

Function Get-SPCalendarWeb(){

	#Clear screen first
	Clear-Host
	
	#Load web where Calendar is supposed to be created
	$web = Get-SPWeb -Identity $webUrl
	Write-Host "SP Web Loaded " $web.Title
	
	#Create new calendar
	New-SPCalendar

	$web.Dispose()
}

Function Add-TestEntries($cal){
	$listItem = $cal.AddItem()
	$listItem["Title"] = "Test 1"
	$listItem["Category"] = $categoriesArray[0]
	$listItem["EventDate"] = [System.DateTime]::Now
	$listItem["EndDate"] = [System.DateTime]::Now.AddHours(4)
	$listItem.Update()
	
	$listItem = $cal.AddItem()
	$listItem["Title"] = "Test 2"
	$listItem["Category"] = $categoriesArray[1]
	$listItem["EventDate"] = [System.DateTime]::Now
	$listItem["EndDate"] = [System.DateTime]::Now.AddHours(4)
	$listItem.Update()
}

Function New-SPCalendar(){
	$web.Lists.Add($listName,"",[Microsoft.SharePoint.SPListTemplateType]::Events)
	$cal = $web.Lists.TryGetList($listName);
	
	Write-Host "Calendar created"
	
	#Delete default categories and add the ones specified in command line
	Add-CalendarCategories $cal
	
	#Add Views with Filters
	Add-SPCalendarViews $cal

	#Add test entries
	Add-TestEntries $cal
}

Function Add-SPCalendarViews($cal){
	$view = $cal.Views["Calendar"]
	$viewFields = $view.ViewFields.ToStringCollection()
	$viewData = ""
    $viewData += ""
    $viewData += ""
    $viewData += ""
    $viewData += ""
	#XML for calendar overlays
	$calendarSettings = "  "
	#To show different color for category views
	$colorIndex = 1 
	
	#Create views for categories so there will be one view for each category
	foreach($category in $categoriesArray){
		#Create filter for the view to show events from the respective category
		$viewQuery = ""
		$viewQuery += ""	
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += %{"{0}" -f $category}
		$viewQuery += ""
		$viewQuery += ""
		$viewQuery += ""
		
		$newView = $cal.Views.Add($category,$viewFields,$viewQuery,3,$false,
			$false,"CALENDAR",$false)
		$newView.ViewData = $viewData
		$newView.Update()

		%{"View created for {0} category" -f $category} | Write-Host
		
		#Update XML for Calendar Overlay, each view would be added as an overlay
		$calendarSettings += %{"  " -f $category}
		$calendarSettings += %{"

Getting authentication prompt again and again while trying to access #SharePoint 2010 Rest Interface

While trying to access to ListData.svc service in a SharePoint 2010 sub site I was getting authentication prompt to enter credentials again and again. I was using a SharePoint Farm administrator account so was sure that permission is not the cause of this problem. So I started SharePoint Manager, browsed to the sub site and saw that there was a problem in a feature

SharePoint Manager Site Feature List

Afterwards I checked in the list nodes of the same site to see which lists were included in this missing feature, after clicking on one of the lists I got the following error which hinted that this list was the one included in the feature.

SharePoint Orphaned list exception

Further in the properties window there was an error message in the content type field

SharePoint Manager List Properties

I deleted this orphaned lists and the service worked fine then.

I hope you found this post helpful. Thanks


Download links for Office Server 2010 and #SharePoint 2010 Service Pack 2 (#SP2) Packages

SharePoint Service Pack 2 (SP2) has been officially released. It was published on 21st July 2013 and contains new updates which improve security, performance, and stability. Please refer the SP2 change list for complete list of fixed issues.

This service pack includes all cumulative updates (CU) from June 2011 till April 2013 and public updates (PU) from July 2011 till May 2013 which were released after Service Pack 1 (SP1)

To download, please click the following links.

Microsoft SharePoint Server 2010 Service Pack 2 KB2687453
Microsoft SharePoint Foundation 2010 Service Pack 2 KB2687464
Microsoft SharePoint Foundation 2010 Language Pack Service Pack 2 KB2687466
Microsoft FAST Search Server 2010 for SharePoint Service Pack 2 KB2687446
Microsoft Search Server 2010 Service Pack 2 KB2687461
Microsoft 2010 Server Language Pack Service Pack 2 KB2687462
Microsoft Office Web Apps Service Pack 2 KB2687470
Microsoft SharePoint and Project Server 2010 Service Pack 2 KB2687452
Microsoft Groove Server 2010 Service Pack 2 KB2687448
Microsoft SharePoint 2010 Indexing Connector for Documentum Service Pack 2 KB2687459
Microsoft Duet Enterprise for SharePoint and SAP Service Pack 2 KB2687445
Microsoft SharePoint Designer 2010 Service Pack 2 (64-bit) KB2687463
Microsoft SharePoint Designer 2010 Service Pack 2 (32-bit) KB2687463

Please note June 2013 CU is not included and has to be installed separately. To download it, please click the following links.

SharePoint Foundation 2010 June 2013 CU

SharePoint Server 2010 June 2013 CU

Thanks for reading and have a nice day. Cheers


Changing SharePoint 2010 lookup column Date Time and Number formatting

Few days back I was creating a report using SharePoint 2010 list as data source in Report Builder 3. The list I was using had the following lookup columns:

  • StartDate (DateTime Column)
  • FinishDate (DateTime Column)
  • Budget (Number)

Now when I tried to change the datetime and number formatting, I noticed formatting was not being applied.

After spending some time I found out that in order to apply number and datetime formatting to lookup columns, they must be converted to a proper data type. So instead of binding field directly to a column, I used the following expressions to convert these lookup columns in proper data types

Convert SharePoint 2010 lookup column to proper data type

The complete list of conversion functions can be found under Common functions and then Conversion. In my case for dates I used CDate(FieldName) and for number column I used CInt(FieldName)

Convert SharePoint 2010 lookup column to proper data type


Why AutoSPInstaller?

Let’s assume we’ve to create a new SharePoint 2010 server so we install SharePoint 2010 and then start the configuration wizard. After we’re through with the configuration wizard, most probably when we’ll start SQL Server Management Studio we’ll see something like the following

SharePoint Databases with Guids

This type of inconsistent naming can be very unpleasant and might not be very handy for our DBAs, wouldn’t it be better if we’d something like

So what we do. We can run some powershell scripts to manually configure our Farm and install services (For more details, please visit http://technet.microsoft.com/en-us/library/cc262839.aspx#section6)

Another good alternate is that we use AutoSPInstaller which can automate the process of installing (including downloading and installation of pre- requisites) and configuring SharePoint 2010 based on inputs we provide in an xml file. There is an editor available to edit scripts for AutoSPInstaller as well called AutoSPInstallerGUI

For detailed instructions on how to use AutoSPInstaller, please visit http://www.softlanding.ca/Blog/Lists/Posts/Post.aspx?ID=30.

Thanks for reading. I hope you found this post useful. Please don’t forget to share this post. Cheers


Changing SharePoint 2010 search box icon using CSS

There are a few ways to change the search box icon like specifying image URL by creating or using existing delegate control and another way to change it on runtime using JavaScript but there is another simpler way so let’s explore it and look at the html for icon which is being generated by the SmallSearchInputBox html control

<a href="javascript:S3031AEBB_Submit()" title="Search" id="ctl00_PlaceHolderSearchArea_ctl01_S3031AEBB_go">
<img style="border-width:0px;" src="/_layouts/images/gosearch15.png" alt="Search" class="srch-gosearchimg" onmouseout="this.src='\u002f_layouts\u002fimages\u002fgosearch15.png'" onmouseover="this.src='\u002f_layouts\u002fimages\u002fgosearchhover15.png'" title="Search">
</a>

We can see that there is an inline img tag inside an anchor tag so if we set the img tag display’s to none and specify background image for the anchor we can easily change icon so let’s try this out. To apply the following CSS, we’ll have to create a CSS in Style Library in which we’ll override default styling and specify it as an alternate CSS in Master page site settings.

td.ms-sbgo
{
padding:0px 3px 0px 3px;
}

td.ms-sbgo a
{
    background-image: url(/Style%20Library/Images/our_search_button.png);
    background-repeat: no-repeat;
    background-position: top left;
    display:block;
    width:20px;
    height:19px;
}

td.ms-sbgo a img
{
    display: none;
}

How to add or remove languages from Advance Search Page in SharePoint 2010

Changing the language list on Advance search page is very simple, just follow these steps.

Step 1: Go to Advance page, site actions and then edit page.

Step 2: Now edit advance search box web part and collapse properties section.

Step 3: Copy xml from properties textbox and paste it in any xml editor like Visual Studio so we can modify it easily

Step 4: Search for languages tag and remove any language that is not necessary from the list. For example let’s remove all languages except English from the list, now it should look like

<Languages>
<Language LangRef="en" />
</Languages>

Step 5: To add another language, just add another Language element with LangRef attribute. Values for LangRef attribute will LangID from the LangDefs element. For example if we want to add Arabic then our Languages element would look like

<Languages>
<Language LangRef="en"/>
<Language LangRef="ar"/>
</Languages>

Step 6: Copy the entire xml and paste it in properties textbox in advance search box web parts (Where we initially copied the xml from) and save the page.

That’s it we are done.

I hope you find this post useful. Thanks


Follow

Get every new post delivered to your Inbox.

Join 140 other followers