8/19/2011

SharePoint Saturday Columbus

 

Last chance reminder! SharePoint Saturday Columbus is tomorrow! If you have not signed up already, it may be full. If you aren’t going and you have signed up, give your ticket to someone else! It will be too good to miss… 30 speakers, 30 topics, lots of networking and cool door prizes!

I’ll be speaking on “SharePoint 2007 and 2010 Customization for Site Owners”. This is an updated version of the presentation I did last year in Columbus. I’ll show you how to easily customize SharePoint without using Visual Studio, custom code or server deployments. And… I have a couple copies of my book to give away, one or two in my session and one or two at the big drawing at the end of the day.

 

 

Don’t forget Cincinnati!

SharePoint Saturday Cincinnati - Saturday, October 29th

 

 

 

 

.

8/18/2011

Access Services – Simple problem, simple fix

 

Access Services – An error has occurred…

 

I “thought” I had everything setup in my test environment that was needed to support Access Services. Then I created a new site based on the “Issues Web Database” template… and got this:

image

 

“An error has occurred”, now there is a useful error message! No question about the cause there! Clicking around the site got me these useful popups:

image

 

Nothing in the Windows Event logs about Access Services. No SharePoint 2010 Correlation ID displayed anywhere. Nothing in the SharePoint logs with the words “Access” or “issues”.

 

The Problem?

 

A bit embarrassing… Access Services was not started.

image 

 

Started the service, and everything worked!

 

I nominate this error message…

as a classic….

    image

 

.

8/17/2011

PowerShell to the Rescue… SharePoint User has no EMail address

 

I’m working with a SharePoint farm where the AD synchronization is not working, and we had a user who for some strange reason did not have an email address in SharePoint and could not get alerts. So while we are working out the AD problem, here’s how I quickly added an email address for this user:

$user = Get-SPUser  domain\username -web http://yourserver/sites/yoursitecollection

`check to see if they have an email address
$user.Email

`set an email address
$user.Email = "user@domain.com"
$user.Update()

Simple… and quick. But you will need to do this for each site collection the user has access to.

 

More on Get-SPUser:  http://technet.microsoft.com/en-us/library/ff607580.aspx

More on the SPUser object that’s returned by Get-SPUser: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.aspx

.More on all of the properties and members of SPUser: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser_members.aspx

 

 

.

8/15/2011

Searching and Auditing SharePoint with PowerShell

 

Last week I gave a presentation to the Dayton SharePoint user group on using PowerShell to search and audit SharePoint. In this article, and one or two follow ups I’ll expand on that presentation.

So what’s here?

  • An overview of permissions needed to use PowerShell with SharePoint
  • How to use PowerShell with both SharePoint 2007 and 2010
  • The SPFarm object and a few of its properties
  • The SPService object

 

Goals:

  • Find info that cannot be found with the out of the box tools
  • Find info that can not be conveniently found with the out of the box tools
  • Collect data for reports
  • Do nothing that is not undoable
  • Do nothing (or as little as possible) that impacts server performance

In this article we are not:

  • Doing administration
  • Doing installs
  • Doing Backups and Restores

PowerShell can do all of this, but those are for other sessions (and other presentors)

 

Permissions:


Not everyone who can start PowerShell can access SharePoint data using the SharePoint 2010 PowerShell cmdlets! PowerShell does not avoid SharePoint security, and actually adds an additional requirement or two.

  • You can use the “setup account” that was used to install SharePoint as it has the rights listed below (but this is not the best practice!)
  • You must be a member of the SQL SharePoint_Shell_Access role
  • You must be a member of the WSS_Admin_WPG local security group on each server
  • You can configure both of the above using one SharePoint PowerShell cmdlet:
        Add-SPShellAdmin –Username “domain/user” -Database “databasename

For SharePoint 2007, just think about which permissions would be needed to otherwise get to the desired content. You will need the same permissions when using PowerShell. Access to the Farm object will require admin permissions. Access to a Site Collection will require Site Collection Administrator, Site Owner, or for some data, Visitor permissions.

 

Memory Management (and possible “manglement!)

 

First the bad news: You have to manage memory. If you don’t, you can crash your SharePoint server by creating objects that are not immediately disposed of. As you drill down into the SharePoint hierarchy you can potentially create thousands of objects.

Different PowerShells, different memory defaults

If running a PowerShell other than the SharePoint 2010 Management Shell, such as the Integrated Scripting Environment (ISE), each command line (each press of the Enter key) runs on a different thread.

         $site = Get-SPSite http://intranet/sites.training
         $site.Dispose()

When the above is run in the ISE the $site object is not been immediately disposed as the request was made on a different thread.

Starting the SharePoint 2010 Management Shell runs this:
      $ver = $host | select version
      if ($ver.Version.Major -gt 1)
          { $Host.Runspace.ThreadOptions = "ReuseThread“ }
      Add-PsSnapin Microsoft.SharePoint.PowerShell
      Set-location $home"

“ReuseThread” causes all commands to now run in the same thread.

 

Memory tools

 

If you would like to track the memory being used by PowerShell you can check the running processes on your PC. PowerShell includes a cmdlet, Get-Process (gps for short) just for this, and it also keeps track of its own process ID in a variable named $PID. You can check the current memory being used with this command:

      gps -id $pid

 

Here’s a sample test:

      `create 100 subsites
      gps -id $pid; 
      for ($i=0; $i -lt 100; $i++) 
      { 
        $s = new-spweb http://intranet/sites/training/PS$i ; 
      } 
      gps -id $pid;

 

Here’s a sample test with dispose:

      `create 100 subsites 
      gps -id $pid; 
      for ($i=0; $i -lt 100; $i++) 
      { 
        $s = new-spweb http://intranet/sites/training/PS$i ;
        $s.dispose(); 
      } 
      gps -id $pid;

 

Sometimes you need to force the garbage collection process if you need to immediately free up RAM. Do not do this excessively as it will be very slow. That said, the following is not best practice!

      `create 100 subsites 
      gps -id $pid; 
      for ($i=0; $i -lt 100; $i++) 
      { 
        $s = new-spweb http://intranet/sites/training/PS$i ;
        $s.dispose(); 
        [System.GC]::Collect());

      } 
      gps -id $pid;

 

Memory - helper functions

If you plan to do much memory usage testing then you may want to create a function or two to save some typing:

PowerShell Process memory:
      function psm
      {
        (Get-Process $pid).PrivateMemorySize/1024/1024
      }

 

Run the garbage collector:
      function cg
      {
        [System.GC]::Collect()
      }

 

Is PowerShell just for SharePoint 2010? Or will it work in SharePoint 2007?

 

SharePoint 2010 includes nearly 600 PowerShell cmdlets. With these you can quickly get a hold of common SharePoint objects with a simple command. Here is how you can get a Site Collection object in one line:

      $site = Get-SPSite http://intranet/sites/training

 

There are no SharePoint PowerShell cmdlets for SharePoint 2007! But that is not too much of a problem as PowerShell can directly access DLLs, including the SharePoint DLLs.

First you will need to load the SharePoint DLL:

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

Then you can use the SharePoint API to create SharePoint objects such as a Site Collection object. The following creates the exact same object as the cmdlet above, and it will work in both 2007 and 2010.

$site = New-Object Microsoft.SharePoint.SPSite(“http://intranet/sites/training”)

 

The SharePoint Hierarchy

 

When looking for a single object in SharePoint (site, list, item, etc) you will often be able to use a single PowerShell cmdlet or API object. But when you want to find all Word documents in all libraries in all site collections in all sites in all web applications, then you will need to drill down through the SharePoint object Hierarchy. Here are the primary objects we will be working with in these articles:

 

SPFarm (the config database)

  SPWebService (Excel services, etc)

    SPWebApplication (IIS app plus a SQL DB)

      SPSite (Site collection)

        SPWeb (a single site)

          SPList & SPLibrary (a single list)

            SPListItem (a single list item)

              SPField (a single property)

 

Each of these objects have their own collections of properties that we can browse through using PowerShell.

 

The Farm

 

As a start, let’s take a look at the top most object in the SharePoint hierarchy, the SPFarm object. Note that the Farm is the Config database, not the collection of physical servers. In fact, the collection of server objects is just one of many properties of the Farm.

For SP 2010:
      Get-SPFarm returns the farm object    (actually the SharePoint Config database)

Or for SP 2007:
      $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

Get the farm:
      $farm = Get-SPFarm

Get the version:
      $farm.BuildVersion              or (Get-SPFarm).BuildVersion

Get the list of servers:
      $farm.Servers                       or Get-SPServer

Get a list of installed Features
      $farm.FeatureDefinitions | sort scope                  or Get-SPFeature

Get a list of installed Solutions
      $farm.Solutions                     or Get-SPSolution

 

Get a list of installed products (or SKUs)

       $farm.Products

This returns a list of GUIDs of the installed products.

Value Product
84902853-59F6-4B20-BC7C-DE4F419FEFAD Project Server 2010 Trial
ED21638F-97FF-4A65-AD9B-6889B93065E2 Project Server 2010
BC4C1C97-9013-4033-A0DD-9DC9E6D6C887 Search Server 2010 Trial
08460AA2-A176-442C-BDCA-26928704D80B Search Server 2010
BEED1F75-C398-4447-AEF1-E66E1F0DF91E SharePoint Foundation 2010
1328E89E-7EC8-4F7E-809E-7E945796E511 Search Server Express 2010
B2C0B444-3914-4ACB-A0B8-7CF50A8F7AA0 SharePoint Server 2010 Standard Trial
3FDFBCC8-B3E4-4482-91FA-122C6432805C SharePoint Server 2010 Standard
88BED06D-8C6B-4E62-AB01-546D6005FE97 SharePoint Server 2010 Enterprise Trial
D5595F62-449B-4061-B0B2-0CBAD410BB51 SharePoint Server 2010 Enterprise
926E4E17-087B-47D1-8BD7-91A394BC6196 Office Web Applications 2010


More info here:

http://blogs.technet.com/b/vedant/archive/2010/10/05/detecting-installed-sku-of-sharepoint-2010-and-upgrading-editions.aspx

 

 

The Services

 

While looking at the SPFarm object let’s take a look at the SPServices object. SharePoint 2010 seems to have an endless list of services. Which are installed on your farm?

SharePoint 2010 does not have a “Get-SPServices” cmdlet, so we will have to get the services object SPFarm object.

      $farm = Get-SPFarm    (or   $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local )

      $farm.Services | select TypeName

Note that the web applications (SPWebApplication) are a special kind “service” (Microsoft SharePoint Foundation Web Application) and can be retrieved using Get-SPWebApplication or by looping through all of the SPService objects and checking the type of service.

 

Next

 

In the next installment we will start looking at, and start exploring, the “everyday” objects such as Site Collections, Webs, Items and Users.

  • Get a list of all site collections
  • Get a list of all sites of type “abc” (blog, Team Site, etc)
  • Get a list of all groups and their users
  • Get a list of all users
  • Get a list of all permissions
  • Get a list of all lists that use Content Type “abc”
  • and a few more...

.

8/08/2011

Speaking at the Dayton SharePoint User Group on Tuesday

 

I will be speaking Tuesday evening, August 9, 2011, at the Dayton SharePoint User Group. The topic will on “Finding Stuff in SharePoint using PowerShell” (formally “Using PowerShell to Audit SharePoint”).

http://www.dayspug.org/

 

Some of the topics covered will include:

  • How to use PowerShell to get a list of all
    • sites in a farm
    • lists that use a selected Content Type
    • sites based on a selected template (blogs, etc)
    • all sites/lists/items with broken inheritance (unique permissions)
    • all Site Collection Administrators from all site collections
    • all installed Solutions
    • all installed Features
    • all products installed (SP edition, Project Server, etc)
    • all users and groups who access to a site
    • and many more

I also have a few donations for the door prize giveaways, including a couple copies of my book SharePoint 2007 & 2010 Customization for the Site Owner, and from MAX Technical Training, tickets to a sporting event and some training discounts!

 

So stop on out!  

Directions here: http://www.dayspug.org 

 

.

7/29/2011

Cincinnati SharePoint User Group Meeting Thursday 8/4/11

 

http://www.CincinnatiSPUG.org/

 

Meeting date:     Aug 4, 2011, Thursday
Time:                   6:00 – 8:00 pm.
Where:                Max Technical Training, 4900 Parkway Dr. #160 Mason, OH.  
                             Directions  http://www.maxtrain.com/directions

 

Schedule:
6:00 – 6:25 - Socials and Networking - No Registration required
6:25 – 6:30 - Introduction of Agenda and Speakers
6:30 – 8:00 – Presentation

 

Session Title: “Caching-In” for SharePoint Performance

Abstract: Caching is a critical variable in the SharePoint scalability and performance equation, but it’s one that’s oftentimes misunderstood or dismissed as being needed only in Internet-facing scenarios.  In this session, we’ll build an understanding of the caching options that exist within the SharePoint platform and how they can be leveraged to inject some pep into most SharePoint sites.  We’ll also cover some sample scenarios, caching pitfalls, and watch-outs that every administrator should know.

Speaker bio: Sean P. McDonough
Bio: Sean is a Product Manager for SharePoint Products at Idera, a Microsoft gold certified partner and creator of tools for SharePoint, SQL Server, and PowerShell.  As a consultant, Sean has worked with a number of Fortune 500 companies to architect, implement, troubleshoot, tune, and customize their SharePoint environments. Sean is an MCPD, an MCTS, and the co-author of both the “SharePoint 2007 Disaster Recovery Guide” and the “SharePoint 2010 Disaster Recovery Guide”.

 

.

7/24/2011

SharePoint 2010: Finding a Unique HTML ID Using the $get Function

 

ID=…

 

Go look up the definition of the HTML ID attribute. The standards say that the ID must be unique in the page. No two elements should share the same ID.  SharePoint frequently breaks this rule. If you have two web parts of the same, or similar, type, they will often each have elements with the same ID. As an example, any web part in 2010 that displays a document icon (Word, Excel, etc) has an anchor tag like this one: <a id="diidSortDocIcon". As a result, the DOM method getElementById will not work as you might hope. While methods like getElementsByTagName (note the “s”) will return a collection of elements, getElementById (note no “s”) either returns null or the first element found with that ID. Bottom line, unless you loop through all of the elements in the page and check each one for that ID, you will only be able to retrieve the first element that uses that ID.

 

$get

To deal with this problem, Microsoft added a function to SharePoint with the name $get(). (Actually I believe this $get is part of the AJAX client side libraries.) This function, when passed a single parameter, will return the first element with that ID in the document. When called with an object as the second parameter, it searches all of the child nodes of that object for an element with that ID and returns the first one it finds.

Here’s what the function code looks like when displayed from an alert():

    image

 

$get("IdToFind",ElementToSearchWithin)

The code displayed above is kind of interesting. If the second parameter is not supplied, then the code just uses getElementById and returns a null or a the single element. If the second parameter is supplied, then the code finds all of the child nodes of the the element listed as the second parameter. It then loops through all of the child elements until it finds one with the ID in the first parameter. (if (a.id == f)

 

As an example, the following will display the innerHTML of the element with the ID of “diidSortDocIcon”, but only if it is found in the element with the ID of “MSOZoneCell_WebPartWPQ6”.


var
mywebpart = document.getElementById(“MSOZoneCell_WebPartWPQ6”) $get("diidSortDocIcon", mywebpart).innerHTML

 

This could also be written as:

$get("diidSortDocIcon",$get("MSOZoneCell_WebPartWPQ6")).innerHTML

 

$get(), just another little tool for your SharePoint customization toolbox!

 

.

7/19/2011

SharePoint: Changing the “Add New” Icon

 

I just got an interesting question on the “Change the “Add New” message for a web part” article about replacing the icon in the Add New Item area of a web part. As CSS does not let you change the attributes of an element (i.e. “src=”), the solution is a bit of a trick.

The before and the after for SharePoint 2007:

image  image

And in 2010:

image    image

The CSS below first hides the existing icon, and then adds a background image to the anchor (“A”) tag. As this results in the text being displayed over the icon, the CSS also needs to add a little padding to move the text over a bit.

The CSS for both 2007 and 2010

Add just before the </head> tag in the master page or in a content editor web part on a single page.

<style>

/*  hide the existing image  */
.ms-addnew img
{
  display:none;
}

/*  add a background image  */
.ms-addnew a
{
  background:url(_layouts/images/titlegraphic.gif) no-repeat;
  padding-left: 25pt;
}

</style>

 

 

.

7/18/2011

SharePoint Saturday Columbus 2011!

 

Join me and thirty other speakers for a free day of SharePoint learning on Saturday August 20th, 2011.

 

Go and check out the list of speakers and register!  It’s FREE!

   http://www.sharepointsaturday.org/columbus/default.aspx

Stolen right from their web site:

Join SharePoint architects, developers, and other professionals that work with SharePoint 2007 and 2010 for SharePoint Saturday Columbus event.  SharePoint Saturday is an educational, informative & lively day filled with sessions from respected SharePoint professionals & MVPs, covering a wide variety of SharePoint-orientated topics.  SharePoint Saturday is FREE, open to the public and is your local chance to immerse yourself in SharePoint!

 

I will be speaking on a subject that I’ve always enjoyed (and what much of this blog is about), “SharePoint 2007 and 2010 Customization for Site Owners”.

This session will get you, the SharePoint Site Owner, started in customizing your SharePoint site. It is not a programming session, but does include some JavaScript coding. It is not a graphics design session, but does include some Cascading Style Sheets. It is not a SharePoint Designer session, but it will make use of it. And nothing requires access to the SharePoint servers.

While the session is for the SharePoint Site Owner, it's also for the developer who does not want to "reinvent the wheel". All you need to apply what you learn here are basic SharePoint skills, how to copy and paste and some puzzle solving skills.

And as I have just released a book on the same topic, I’ll be brining a few copies to give away! If you don’t want to wait until August, you can get it at Amazon (with free shipping) or until the end of July, directly from the publisher with a 25% discount (with this code: 77ULP6VH).

 

 

.

7/15/2011

SharePoint 2007: Moving the View Dropdown for Wide Lists

 

One of the annoying “features” of SharePoint 2007 is how the View dropdown gets pushed off of the page when working with list views with many columns.

 

Left part of the page:

image

One scroll to the right:

      image

Two scrolls to the right and we can now find the view menu:

            image

 

What would be nicer would be a View menu just to the right of the other toolbar buttons.

image

 

All we need to do is write a little JavaScript to find the toolbar TABLE and adjust the column widths.

Steps for a single view page:

  1. Display the list’s view page
  2. Click Site Actions, Edit Page
  3. Add a Content Editor Web Part and move it to the bottom of the page (below the list’s web part)
  4. Edit the Content Editor Web Part, click the Content Editor button and paste in the following JavaScript
  5. Save everything and test!

Steps for all lists, pages and views:

  1. Open SharePoint Designer and open your site
  2. Open your master page (typically default.master)
  3. Scroll to the bottom of the page and click just before the </body> tag
  4. Paste the following JavaScript
  5. Save everything and test!

 

<script>
// from TechTrainingNotes.blogspot.com
// find all tables var x = document.getElementsByTagName("table"); for (var i=0;i<x.length;i++) { // find the table with this class if (x[i].className=="ms-menutoolbar") { // change the widths of all of the cells to 0 for (var j=0; j<x[i].rows[0].cells.length;j++) { x[i].rows[0].cells[j].style.width="0" } // change the width of the last column x[i].rows[0].cells[j-1].style.width="100%" } } </script>

I tried to solve this little problem by using CSS instead of JavaScript. I got close, but ended up with an empty cell at the end of the row. So, let me know if you find a CSS solution.

<style>

.ms-listheaderlabel
{
  width:100%
}
.ms-menutoolbar
{
  width:0;
}
</style>

 

.

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.