Why PowerShell and SharePoint 2010 Are So Cool


Anybody who has read one of my posts knows that I am a huge PowerShell geek, I tweet about it, I blog about it, I talk about it SO much at my client that my contacts at said client make me add a dollar to the “PowerShell Jar” whenever I use the word “PowerShell.” 🙂

People who don’t ‘touch’ SharePoint may not completely understand why PowerShell and SharePoint are so cool, so I wanted to put together a quick, fairly non-technical post about why they are so cool…

  1. PowerShell allows SharePoint Developers and IT Pros to automate tasks that in the past would’ve required a LOT of scripting – however, we can do it much, much quicker and easier in PowerShell.
  2. PowerShell allows SharePoint IT Pros access to something that in the past we haven’t had easy access to – the SharePoint API or Object Model. (Note: I’m not a developer so if I use a term incorrectly, forgive me. :))

#1 is fairly obvious, but #2 is really where the power comes in.  There are times when an IT Pro is administering SharePoint and he or she needs to do something that just isn’t possible in the UI or through the standard command interfaces.  Having the ability to call methods from the SP Object Model in PowerShell takes away a lot of headaches!

Example: I need to forcefully delete a service application but can’t do so because I blew away the database.  Remove-SPServiceApplication won’t work at this point because that’s the graceful way to do it and I can’t communicate with the service application database.

Resolution:

$app = Get-SPServiceApplication -Identity
$app.Delete()

That’s right, two quick lines of code and I’ve now deleted the old service application that I couldn’t delete using Remove-SPServiceApplication or through the Central Administration interface.

For other examples of using PowerShell and the Object Model to accomplish tasks that in prior (non-PowerShell-enabled) versions were not possible without code – see one of my other recent posts…

Advertisements

Adding Ratings to the Search Results Page in SharePoint 2010


One of the most requested features for SharePoint 2010 was the ability to rate content. That functionality has been provided, but one place where it is lacking out of the box is Search.

A quick {insert search provider here} search will yield several very good results for how to add Ratings to Search, but unfortunately not one source was able to tell the whole story.

I intend to do so… 🙂

High-Level Steps
1. Turn on ratings in at least one document library.
2. Add the managed metadata properties.
3. Customize the Advanced.aspx page.
4. Customize the Search Core Results Web Part on the Results.aspx page.
5. Customize the Refinement Panel Web Part on the Results.aspx page.
6. Search!

Enabling Ratings
1. Navigate to a document library.
2. From the ribbon, choose Library Settings.
3. Click Rating Settings.
4. Select Yes to enable ratings, click OK.
5. !Required! Run a Full Crawl
6. Proceed to the next section…

Adding the Managed Metadata Properties
1. Login to Central Administration > Manage Service Applications > Search Service Application.
2. Click Metadata Properties in the Quick Launch.
3. Click New Managed Property.
4. Enter Rating for the Property Name, select Decimal as the type, click Add Mapping and choose ows_AverageRating(Decimal) as the Crawled property; click OK.
5. Click New Managed Property.
6. Enter Rating Count for the Property Name, select Integer as the type, click Add Mapping and choose ows_RatingCount(Integer) as the Crawled property; click OK.
7. !Required! Run a Full Crawl

Customizing the Advanced Search Page
1. Go to your Search Center, and click Advanced.
2. Open the page in Edit mode.
3. Edit the Advanced Search Box Web Part and expand Properties, copy all of the text in the Properties field and paste it into an XML editor.
4. Add the following PropertyDef reference in the PropertyDefs section:

5. Add the following PropertyRef reference in the ResultTypes section:

6. Copy and Paste all of your XML back into the Properties field, save the web part and your page.

You should now be able to perform advanced searches using the Rating column:

Customizing the Search Core Results Web Part
1. In your Search Center, do a quick search to get to /Pages/Results.aspx.
2. Open the page in Edit mode.
3. Edit the Search Core Results Web Part and expand Display Properties, if this is your first edit of this web part, you will need to uncheck Use Location Visualization.
4. Edit the Fetched Properties by adding the two new Managed properties to this list:
and .
5. Click XSL Editor and copy/paste all of the code into an XML editor to customize the XSLT.
6. Insert the following code right before the

<div class="srch-Description2">

tag:

<!--Start Rating-->

                <div class="ratingDiv">

                <xsl:call-template name="FormatRating">  

                <xsl:with-param name="theRating" select="rating" />  

                <xsl:with-param name="theRatingCount" select="ratingcount" />

                </xsl:call-template>  

                </div>

<!--End Rating-->

7. Insert the following code right before the very last tag:

<xsl:template name="FormatRating">  

<xsl:param name="theRating" />  

<xsl:param name="theRatingCount" />  

<xsl:if test="$theRating > 0">  

<div style="display: inline-block; padding-left: 24px;">  

<div>  

<xsl:variable name="tempTitle" select="concat($theRating, ' Stars (')"/>  

<xsl:variable name="tempTitle2" select="concat($theRatingCount, ' Ratings)')"/>  

<xsl:variable name="ratingTitle" select="concat($tempTitle, $tempTitle2)"/>  

<xsl:attribute name="title">  

<xsl:value-of select="$ratingTitle"/>  

</xsl:attribute>  

<xsl:choose>  

<xsl:when test="round($theRating) = 0 and $theRating > 0">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-368px 0px;width:16px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 1 and round($theRating) &lt;= $theRating">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-352px 0px;width:16px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 2 and round($theRating) > $theRating">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-352px 0px;width:32px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 2 and round($theRating) &lt;= $theRating">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-336px 0px;width:32px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 3 and round($theRating) > $theRating">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-336px 0px;width:48px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 3 and round($theRating) &lt;= $theRating">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-320px 0px;width:48px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 4 and round($theRating) > $theRating">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-320px 0px;width:62px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 4 and round($theRating) &lt;= $theRating">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-304px 0px;width:64px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 5 and round($theRating) > $theRating">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-304px 0px;width:80px;</xsl:attribute>  

</xsl:when>  

<xsl:when test="round($theRating) = 5">  

<xsl:attribute name="style">background-image:url(/_layouts/images/Ratings.png);cursor:default;height:16px;margin:0px;background-repeat:no-repeat;background-position:-160px 0px;width:80px;</xsl:attribute>  

</xsl:when>  

</xsl:choose>  

</div>  

</div>  

</xsl:if>  

</xsl:template>  

<!--End Rating-->

8. Copy and Paste all of your XML back into the XSL Editor, save the web part and your page.

1. In your Search Center, do a quick search to get to /Pages/Results.aspx.
2. Open the page in Edit mode.
3. Edit the Refinement Panel Web Part and expand Refinement.
4. Uncheck Use default configuration.
5. Copy/paste all of the code from the Filter Category Definition into an XML editor to customize the XSLT.
6. Modify one of the existing Category definitions, and modify it. Here’s what mine looks like:

7. Copy and Paste all of your XML back into the XSL Editor, save the web part and your page.

Search
1. Do a search for something which should yield content which you have rated.
2. You should not only see ratings IN the search result content, but you should be able to refine your results by the rating, COOL!

Important: I wouldn’t have gotten nearly this far without the following two sources:
1. http://todd-carter.com/post/2010/10/05/Pimp-Document-Ratings-within-SharePoint-Search-Results.aspx
2. http://blogs.technet.com/b/speschka/archive/2009/10/28/using-the-new-sharepoint-2010-ratings-feature-in-search.aspx

PDFs no longer open in browser in SharePoint 2010


In MOSS, if you navigated to a library or performed a search for a PDF; you could click on it to open it right up in the browser. That is of course if you have Adobe Reader. 🙂

In 2010, if you do the same thing your used to, you will be prompted with the option to Save or Cancel.

To get the auto-open behavior back, go to Central Administration>Application Management>Manage Web Applications.

Click on the Web Application to select it, and click General Settings.

In the Web Application Settings dialog window, scroll down to Browser File Handling and change the setting from Strict to Permissive, and click OK.

Your PDF files should now open automatically as they did in previous versions of SharePoint.

Enterprise Search Center Funkiness in SP2010 Server


I am working on building a SharePoint Server 2010 Enterprise environment for Demonstration purposes. I applied my custom branded AdventureWorks master page and created a Search Center sub-site like I always do.

I then uploaded some sample documents and performed a Full Crawl. After the crawl completed I opened the site in my browser and attempted a search for what I knew would return results, only no results were found.

Interestingly enough, I then performed the same query FROM the Search Center site and it found 74 results. Weird, I thought. I then noticed in the query string was: http://AWDemo/searchcenter/pages/Results.aspx?k=sharepoint&cs=This%20Site&u=http%3A%2F%2Fawdemo

The &cs=This%20Site&u=http%3A%2F%2Fawdemo portion of the query string was what concerned me so I went to the Search Settings page and checked my settings.

I had the following settings which I expected would work based on my previous experiences:

Enabled Custom Scopes
/searchcenter/pages

Do not show scopes dropdown, and default to contextual scope

/searchcenter/pages/results.aspx

Just to test I changed the middle dropdown from Do not show scopes dropdown and default to contextual scope to Do not show scopes dropdown and default to target results page.

I attempted another search from my home page search box and voila, it worked just as I would expect.

Add simple, one-column list search functionality to SharePoint


Awhile back I was working with a client who needed to manage a simple, two-column custom list. The task was simple, manage company acronyms. The list took no time to create as I imported it from the source spreadsheet, it was two columns; Acronym and Acronym Meaning.

The cool, easy solution was this:

1. Create a new page
2. Add 3 Web Parts to the page, List View (viewing the Acronym list), Form Web Part and Content Editor Web Part.
3. Configured the Form Web Part to connect to the List View WP on the Acronym column.
4. Configured the CEWP with a link to Add A New Acronym (in case the acronym they were searching for didn’t exist)

The final product allowed a user to enter an acronym (AD for example) and it would pull back the appropriate acronym, i.e.:

AD – Active Directory

Quick, simple solution for employees to quickly search acronyms.