Thursday, 17 April 2014

How to call and pass parameter from one PowerShell script file to another?

I came across a scenario where I have to call another PowerShell script file and pass the current PowerShell script file input parameter to this second file.

PowerShell as the name says is very powerful and I was able to achieve my requirement with a simple expression called as "Invoke-Expression" in PowerShell.

Just to explain you how I have achieved my above requirement, I have created two demo PowerShell files called First.ps1 and Second.ps1. I am gonna show you how I have called First.ps1 and invoke the Second.ps1and pass the First.ps1 input parameter to the Second.ps1 with "Invoke-Expression".



Hope this is helpful.
Cheers!!
Isha Jain

Monday, 31 March 2014

Upgrade Search Settings and result sources using PowerShell in SharePoint 2013

I came up with a requirement where I want the user to search the results only from the site collection level. In SharePoint 2010, we all know there are search scopes which help us to narrow down our search based on content sources, web address and metadata. However; there is no search scopes in SharePoint 2013. There is a new concept similar to Search Scope called as Search Result Sources.

This Result sources can be created at "Application Level", "Site Collection Level" and "Site Level".

You could find more information on Result Sources in SharePoint 2013 @ http://technet.microsoft.com/en-us/library/dn186229(v=office.15).aspx

I decided to script out the following
1. Creation of Enterprise Search Centre site
2. Update the search settings to point to this new search centre instead of default OSSSearchResults page.
3. Create a site collection level result source
4. Update the search results webpart properties to query only at above created site collection result source.

1. Create Enterprise Search Centre via PowerShell

Note: you need to activate the "BaseSite" Collection hidden feature before creating the search centre.
2. Settings the results page for your above search centre

3. Create a Site Collection level result source

4. Update the search results webpart to use this above result source for query.

Hope you like my approach.
enjoy!!
Isha Jain

Runtime error when creating SharePoint 2013 Pulishing site

Today, I received a very strange error when creating a sub publishing site in SharePoint 2013. I received the below error runtime error with the famous yellow screen.



I am surprised to see this error and I have full control to the site and uls logs says access denied to one of the mobile channel list. I wondered what is mobile channel list is, then after much searching I have found that there is a new feature introduced in SharePoint 2013 called device channels.

With Device channel in SharePoint 2013, you can render a single publishing site in multiple ways by using different designs that target different devices like Mobile, i-Pad etc.

In order to resolve this error, you need to grant at least read only access to all the users to this device channel list or break the unique permissions to this list. Device channel list is hidden and can be accessible via site settings -> Device Channels




Thus to solve the above error while creating the sub publishing site, at least provide read only permission to sub site owners at device channel list.

Hope this must have saved lot of your time.

Cheers,
Isha Jain



 

Friday, 15 November 2013

Add Custom Web Parts to a page and Connect them using PowerShell


These days I am working heavily on SharePoint CSOM and BCS (Business Connectivity Services). I have created a sandbox package with multiple custom business data and html form data web parts.

The reason why I am writing this blog is to share with you some of the cool stuffs I did with PowerShell in the project.

I have written many automation scripts to create web part page, add web parts to this page and then connect to them on a single click using PowerShell.

First thing first…

1.       Create a web part page using PowerShell:



2.       Add web part to this page:



3.       Connect web parts in a page: In this script I have shown how we can connect

a.       Query String filter Web Part with Business Data List Web Part

b.      Query String filter Web Part with Business Data Item Web Part

c.       Business data List Web Part with Business Data Item Builder Web Part

 



Have Fun!

Isha Jain

Thursday, 25 April 2013

Paste content into SharePoint with no formatting

Hello Again,

These days I am working heavily into SharePoint Ribbon customization. If you have not read my previous blog on this, I would recommend you to read Previous Ribbon Blog before reading this one.

SharePoint 2010 brings the new evolution in user interface and have brought common functionalities into same page by introducing the Ribbon concept.

In SharePoint user is allowed to copy content from various sources like email, office applications like word, excel  and paste into SharePoint.

By default there are two ways to paste content into SharePoint from ribbon.


1. Paste (paste content with styles and formatting)
2. Paste palintext (paste content without styles but keeps the formatting)


However; pasting the content even as Plain text from word and other sources into SharePoint  introduces breaks and other markup issues in Html.

Paste  (format:break line and color:Blue)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null
Write-Host "Hello All"

Paste Plaintext (only format:break line)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null
Write-Host "Hello All"

I wanted to achive something shown below.

Paste with no formatting (no format no color)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null Write-Host "Hello All"



I have created a sandbox solution and added element.xml as shown below. On click of this flyout anchor menu I have called a javascript function as defined in commandaction attribute in the command handler.

Hope you find this useful.
Cheers,
Isha Jain

Friday, 5 April 2013

How to find a SharePoint field from GUID

Hello,

I have been in a scenario where I need to find one of the SPFields from its GUID. Its again PowerShell who saves my time.


$site = Get-SPSite -Identity "http://Site"
$web=$site.RootWeb
$field=$web.Fields[[Guid]"E9359D15-261B-48f6-A302-01419A68D4DE"]

That's it, I am done!!!

Cheers,
Isha Jain

Monday, 25 March 2013

Find all the sites where the feature is activated

Hi,

I have been struggling how to find out the lists of sites where my feature is deployed.

Below PowerShell command which helped me.



Instead of  using "Write-Host", I have used "Write-Output" which will give output in my output.txt file.

Note: Write-Host will write the output in the console while Write-Output helps to write the output in some file.

Hope this is useful.
Cheers,
Isha