8/24/2012

SharePoint PowerShell cmdlets Equivalents for SharePoint 2007

 

SharePoint 2007 administrators may feel a bit left out when the see all of the articles showing how to do quick and powerful things with SharePoint 2010 PowerShell cmdlets. In this article I will show how to create common SharePoint objects without using the cmdlets.

This article is not done… I will be adding to it. Let me know if you need any other cmdlet replacements. When I get a chance I'll wrap up and publish my collection of 2007 "cmdlets" so you can generally just use the 2010 scripts.

 

Most of the examples below are in the form of "replace this cmdlet based code fragment with this SharePoint API fragment".

 

Hooking PowerShell to the SharePoint API

For all of the following script samples start your script with this line:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

This line is only need once at the beginning of your script.

 

Get-SPFarm

Replace:
  $farm = Get-SPFarm

With:
   $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

Notes:

  • The cmdlet's default property is the name of configuration database. OM's default return is a list of all properties.
  • The output of the above can be piped just like Get-SPFarm.
      [Microsoft.SharePoint.Administration.SPFarm]::Local | select servers
    or
      $farm | select servers

 

Get-SPSite

Returned Data with URL parameter

Replace:
  $site = Get-SPSite http://intranet

With:
  $site = New-Object Microsoft.SharePoint.SPSite("http://intranet")

Notes:

  • The cmdlet's default property is the Url of the site collection. OM's default return is a list of all properties.
  • The output of the New-Object can be piped to another cmdlet just like Get-SPSite. You cannot pipe into New-Object.

 

Target of a Pipe passing a SPWebApplication or a collection of SPWebApplications

Replace:
$webapplication | Get-SPSite

With:
$webapplication | select -ExpandProperty Sites

Examples:
  2010: $webapplication | Get-SPSite | Select url, {$_.rootweb.title}
  2007: $webapplication | select -ExpandProperty Sites | Select url, {$_.rootweb.title}

 

Get-SPWeb

Returned Data with URL parameter

Replace:
  $site = Get-SPWeb http://intranet/sailboat

With:
  $web = (New-Object Microsoft.SharePoint.SPSite("http://intranet/blog")).OpenWeb()
or
  $web = (New-Object Microsoft.SharePoint.SPSite("http://intranet")).allwebs["sailboat"]

Notes:

  • The above is identical to the Get-SPSite replacement with the addition of .OpenWeb().
  • Get-SPWeb typically is used with "-Limit All" to display more than 20 webs. That is not needed with the 2007 equivalent which will always return all webs.

 

Target of a Pipe passing a collection of SPSites

Replace:
  collectionOfSites | Get-SPWeb

With:
  collectionOfSites | select -ExpandProperty AllWebs

Examples:
  2010: $webapplication.Sites | Get-SPWeb | Select title, url
  2007: $webapplication.Sites | select -ExpandProperty AllWebs | Select title,url

 

Get-SPWebApplication

Returned Data using URL parameter

Replace:
  $webApplication = Get-SPWebApplication http://servername

With:
$webApplication = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("http://servername")

 

Returned Data without parameter (return all web apps)

Replace:
$webApplications = Get-SPWebApplications

With:
$webApplications = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.WebApplications

 

more to come…

8/22/2012

SharePoint: PowerShell to find all Content Types that use a Site Column

 

Just another little PowerShell script for SharePoint…

The following will report all Content Types in a single Site Collection that uses a particular Site Column.

This is related to this article PowerShell to find SharePoint Content Types.

 

The Script:

$site = Get-SPSite http://sharepoint/sites/training   #your URL here!
$web = $site.RootWeb

# Get the GUID of your Site Column
$guid = $fields["End Time"].id            # your Site Column name here

# Find all content types that use that column type
#  This will display all content types and list details if there match for the column


$ct = $web.AvailableContentTypes 
for ($i=0; $i -lt $ct.Count; $i++) 
{
  for ($j=0; $j -lt $ct[$i].Fields.Count; $j++) 
  {
    if ($ct[$i].Fields[$j].id -eq $guid)
    {
      Write-Host $ct[$i].Name " has column"
    }
  }
}

 

For SharePoint 2007 replace the first line with these two:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$site = New-Object Microsoft.SharePoint.SPSite(http://yourserver/sites/yoursite)

 

.

SharePoint 2010 - Create a Calendar View without Hyperlinks

 

This article is one of the many tips in my book, SharePoint 2007 and 2010 Customization for the Site Owner, and presented here as a response to an MSDN forum question. So if this is useful to you… buy the book!

A 2007 version is here and in a lot more detail in my book.

 

We often need a calendar view that is just a "calendar view". I.e. no hyperlinks, just text.

In SharePoint 2010 the data for the calendar is asynchronously loaded using a SharePoint built-in JavaScript function called after the page is loaded. That means that the data we want to change is not yet in the browser when the JavaScript is loaded from within the Content Editor Web Part. To get our code to run at the right time we need to hook into the SharePoint function that loads the calendar items. This is a function named "SP.UI.ApplicationPages.CalendarNotify.$4a".We also need to delay the load of our code, and we can do that with a SharePoint feature named "_spBodyOnLoadFunctionNames.push".

Two Solutions!

Content Editor Web Part

Add a Content Editor Web Part as we have done in many of the other customizations. The problem with this approach is that SharePoint 2010 will no longer treat this page as a view. When this page is displayed you will see two changes:

  • The View dropdown list in the site title area is missing
  • The ribbon will not be displayed when the page is first loaded, but will be displayed when any event item is clicked.

SharePoint Designer

Add the custom JavaScript using SharePoint Designer. The page will then display as an ordinary view with no odd behavior.

I recommend the second approach.

 

Steps - Using SharePoint Designer
  1. Go to the calendar in the browser and create a new view (maybe "Calendar - No Links")
  2. Open your site in SharePoint Designer 2010
  3. Click Lists and Libraries in the Site Objects pane
  4. Click your calendar list and click the new view
  5. In the ribbon click the Advanced Mode link (so you can edit the entire page)
  6. Search for "</WebPartPages:WebPartZone>" and insert a new line just after this tag
    </WebPartPages:WebPartZone>
    your customization goes here (don't type this J )
    </asp:Content>
  7. Add the JavaScript from below
  8. Save your changes in SharePoint Designer
  9. Go to the calendar in a browser, select the new view and confirm that the hyperlinks have been removed

 

Steps - Using a Content Editor Web part
  1. Open Notepad and add the JavaScript from below and save the file (maybe "HideCalendarLinks.txt")
  2. Upload the file to a library (I use a library named CustomziationFiles)
  3. Right-click the new library file, click Properties and copy the URL to the file
  4. Go to the calendar in the browser and create a new view (maybe "Calendar - No Links")
  5. After the new calendar view has been displayed click Site Actions, Edit Page
  6. Add a Content Editor Web Part
  7. Move the new web part below the calendar web part
  8. Edit the web part and paste the URL to the text file uploaded earlier into the Content Link box
  9. Click OK to save the change, then in the Page tab of the ribbon click Stop Editing
  10. Go to the calendar, select the new view and confirm that the hyperlinks have been removed

 

Code to hide the links

Code note!  Prior to service pack 1 you will need to use SP.UI.ApplicationPages.CalendarNotify.$4a while after service page 1 you will need to use SP.UI.ApplicationPages.CalendarNotify.$4b.

<script type="text/javascript">

// TechTrainingNotes.blogspot.com
// Sample code from "SharePoint 2007 and 2010 Customization for the Site Owner"
// ISBN: 978-0982899205
// http://www.amazon.com/dp/0982899203/ref=as_li_ss_til?tag=tectranot-20&camp=213381&creative=390973&linkcode=as4&creativeasin=0982899203&adid=0cc7a0y6fv2nknxyqvff&


// load our function to the delayed load list
_spBodyOnLoadFunctionNames.push('hideCalendarEventLinkIntercept');

// hook into the existing SharePoint calendar load function
function hideCalendarEventLinkIntercept()
{
  var OldCalendarNotify4a = SP.UI.ApplicationPages.CalendarNotify.$4b;
  SP.UI.ApplicationPages.CalendarNotify.$4b = function () 
    {
      OldCalendarNotify4a();
      hideCalendarEventLinks();
    }
}

// hide the hyperlinks
function hideCalendarEventLinks()
{

  // find all DIVs
  var divs = document.getElementsByTagName("DIV");
  for (var i=0; i<divs.length; i++)
  {
    // find calendar item DIVs
    if (divs[i].className.toLowerCase() == "ms-acal-item")
    {
      // find the hyperlink
      var links = divs[i].getElementsByTagName("A");
      if (links.length == 1)
      {
        // replace the hyperlink with text
        links[0].parentNode.innerHTML = links[0].innerHTML
      }
    }

    // find "x more items" links and re-remove links on Expand/Contract
    if (divs[i].className.toLowerCase() == "ms-acal-ctrlitem")
    {
      var links = divs[i].getElementsByTagName("A");
      if (links.length == 1)
      {
        links[0].href = "javascript:hideCalendarEventLinks();void(0);"
      }
    }

  }
}

</script>

 

 

.

8/17/2012

Cincinnati SharePoint User Group Lightning Rounds!

 

6:00 PM 9/6/2012 at MAX Technical Training

http://www.CincinnatiSPUG.org

Lightning Rounds (You can be a speaker too!)

The Cincinnati SPUG September meeting will feature what we call a Lightning Round session where each presenter will have 5 to 15 minutes to present on anything related to SharePoint. We do this just for fun, and as a great way to get people with SharePoint expertise to start speaking at SharePoint events. PowerPoints are optional, five slides or less and just talk about something cool you've done with SharePoint. (We stole the idea from the Columbus SPUG and the Dayton SPUG stole it from us!)

If you are in the Cincinnati area, and would like to try your hand at speaking, let me know. (Post a message below with your email and I'll get back to you. Your reply and email will not be displayed.)

All SharePoint nuts are welcome to attend, even if you are not speaking.

Logo created by Michael Hiles

.

Final Reminder! First Ever Cincinnati PowerShell User Group Meeting 8/28!

 

Tuesday, August 28, 2012, 6:00 PM to 8:00 PM (add it to your calendar NOW!)

It's free! Go here and register NOW!
http://www.meetup.com/TechLife-Cincinnati/events/75092962/
(Registration is not required, but will help us plan for the event, order pizza and spread the word.)

Speaker is scheduled, SWAG is being acquired, people are signing up.

Ed Wilson, the Microsoft Scripting Guy and a well-known scripting expert, will be the kick off speaker for the new Cincinnati PowerShell user group. His topic will be "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation".

Goodies are on the way from Microsoft Press, O'Reilly, APress and others! Free books, discounts, and other stuff, all to be given away as door prizes. (But I know you are coming to hear Ed speak, not to win door prizes!)

Come prepared to network, talk PowerShell and even volunteer to support this new user group!

 

Spread the word!

Let your coworkers know. Blog and Tweet about it. (#cincypowershell should work)

 

Ed's Topic "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation"

There are four different ways to manage a remote Windows 8 workstation. The first is to use WMI remoting, the second is to use the computername cmdlets, the third is to use WinRm and Windows PowerShell native remoting, the last way is to use the CIM cmdlets. Each approach has advantages and disadvantages for the network administrator. In this session, I will examine each approach, and provide a checklist of criteria to aid the enterprise network administrator in choosing the appropriate technology for a variety of real world scenarios. This presentation combines live demo’s and interactive discussion to heighten learning.

About the presenter:

Ed Wilson is the Microsoft Scripting Guy and a well-known scripting expert. He writes the daily Hey Scripting Guy! blog. He has also spoken multiple times at TechEd as well as at the Microsoft internal Tech Ready and Geek Ready conferences. He has also spoken at the first SQL Rally conference in Orlando, as well as at numerous SQL Saturday events. He is a Microsoft-certified trainer who has delivered a popular Windows PowerShell workshop to Microsoft Premier Customers worldwide. He has written 9 books including 6 on Windows scripting that were published by Microsoft Press. He has also contributed to nearly a dozen other books. His Windows PowerShell 2.0 Best Practices book for Microsoft Press is currently a best seller. Ed holds more than 20 industry certifications, including Microsoft Certified Systems Engineer (MCSE), the Microsoft Certified Data Base Administrator (MCDBA) and Certified Information Systems Security Professional (CISSP). Prior to coming to work for Microsoft, he was a senior consultant for a Microsoft Gold Certified Partner where he specialized in Active Directory design and Exchange implementation. In his spare time, he enjoys woodworking, underwater photography, and scuba diving.

.

8/04/2012

Which Excel, Visio and other Office products can "Publish" to SharePoint

 

A frequent question I get is "I can't publish to SharePoint". Not all editions of Excel and Visio have the publish feature!

Excel and Excel Services

Any edition of Excel can save files to a SharePoint library. Only the following editions of Excel 2010 can publish to Excel Services:

  • Microsoft Office Professional Plus 2010
  • Microsoft Office Professional Academic 2010
  • Microsoft Excel Stand-Alone 2010

Details: http://support.microsoft.com/kb/2569945

 

Visio and Visio Services

Any edition of Visio can save files to a SharePoint library. The edition needed to use Visio with other SharePoint features varies:

  • SharePoint Workflow import and export through SharePoint Designer 2010: Premium
  • Visual mash-ups with Visio Services: Professional and Premium
  • Publishing of diagrams to SharePoint Process repository: Standard, Professional and Premium
  • Publishing Visio Web (.vdw) drawings to SharePoint: Professional and Premium
  • Automatic Data Linking to data sources in SharePoint: Professional and Premium
  • Real-Time sharing of dynamic, data-driven diagrams via a browser using Visio Services: Professional and Premium

Details: http://visio.microsoft.com/en-us/TryBuy/Pages/Edition_Comparison.aspxhttp://technet.microsoft.com/en-us/library/ee663485.aspx and http://office.microsoft.com/en-us/visio-help/save-diagrams-to-sharepoint-as-web-drawings-HA010357073.aspx

 

SharePoint 2010 Services and Features by edition:

http://sharepoint.microsoft.com/en-us/buy/Pages/Editions-Comparison.aspx

 

.

7/26/2012

New Cincinnati PowerShell User Group!

 

Tuesday, August 28, 2012, 6:00 PM to 8:00 PM (add it to your calendar NOW!)

Ed Wilson, the Microsoft Scripting Guy and a well-known scripting expert, will be the kick off speaker for the new Cincinnati PowerShell user group. His topic will be "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation".

Come prepared to network, talk PowerShell and even volunteer to support this new user group!

It's free! Go here and register!
http://www.meetup.com/TechLife-Cincinnati/events/75092962/

Registration is not required, but will help us plan for the event, order pizza and spread the word!

 

Ed's Topic "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation"

There are four different ways to manage a remote Windows 8 workstation. The first is to use WMI remoting, the second is to use the computername cmdlets, the third is to use WinRm and Windows PowerShell native remoting, the last way is to use the CIM cmdlets. Each approach has advantages and disadvantages for the network administrator. In this session, I will examine each approach, and provide a checklist of criteria to aid the enterprise network administrator in choosing the appropriate technology for a variety of real world scenarios. This presentation combines live demo’s and interactive discussion to heighten learning.

 

About the presenter:

Ed Wilson is the Microsoft Scripting Guy and a well-known scripting expert. He writes the daily Hey Scripting Guy! blog. He has also spoken multiple times at TechEd as well as at the Microsoft internal Tech Ready and Geek Ready conferences. He has also spoken at the first SQL Rally conference in Orlando, as well as at numerous SQL Saturday events. He is a Microsoft-certified trainer who has delivered a popular Windows PowerShell workshop to Microsoft Premier Customers worldwide. He has written 9 books including 6 on Windows scripting that were published by Microsoft Press. He has also contributed to nearly a dozen other books. His Windows PowerShell 2.0 Best Practices book for Microsoft Press is currently a best seller. Ed holds more than 20 industry certifications, including Microsoft Certified Systems Engineer (MCSE), the Microsoft Certified Data Base Administrator (MCDBA) and Certified Information Systems Security Professional (CISSP). Prior to coming to work for Microsoft, he was a senior consultant for a Microsoft Gold Certified Partner where he specialized in Active Directory design and Exchange implementation. In his spare time, he enjoys woodworking, underwater photography, and scuba diving.

.

7/16/2012

SharePoint: Lost a bet to myself!

 

After skipping unlucky version 13 and jumping from version 12 to version 14 I was certain that Microsoft would call the next version of Office and SharePoint anything other that 2013.  Oh well…

 

(my shortest post of the year?)

 

.

SharePoint 2013 MSDN / TechNet Forums are up

 

As you start downloading and installing SharePoint 2013 (you are aren't you???) and have questions you may want to post them to these forums:

SharePoint 2013 Preview for IT Professionals

Use this forum to ask questions and comment about SharePoint 2013 Preview as it pertains to setup, deployment, administration, and other IT Professional issues.

SharePoint 2013 Preview for Developers

Use this forum to ask questions and comment about SharePoint 2013 Preview as it pertains to development, customization, and other Developer issues.

Developing Apps for SharePoint

Use this forum to ask questions and comment about developing apps for SharePoint 2013.

The Office 365 Forums

http://community.office365.com/en-us/preview/forums/default.aspx

 

.

7/09/2012

Spam, spam, spam…

 

This is just a placeholder to see how many blog spammers post without reading.  Smile

All responses to this blog are moderated and all spam posts are flagged as spam so blogger/google can pre-mark them as spam for other bloggers.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.