Thursday, January 31, 2013

SharePoint 2010 PowerShell Scripts I Use Frequently


Get-SPSite

Returns all site collections that match the given criteria.

The Get-SPSite cmdlet returns either a single site that matches the Identity parameter, or all the sites that match the Filter parameter for the specified scope. The scopes are the WebApplication, ContentDatabase , and SiteSubscription parameters. If none of these scopes is provided, the scope is the farm. If the scope is specified with no Filter parameter, all sites in that scope are returned.

Get-SPSite [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Filter <ScriptBlock>] [-Limit <String>] [-WebApplication <SPWebApplicationPipeBind>] [-WhatIf [<SwitchParameter>]]
Get-SPSite [-Identity] <SPSitePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Filter <ScriptBlock>] [-Limit <String>] [-Regex <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
Get-SPSite -ContentDatabase <SPContentDatabasePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Filter <ScriptBlock>] [-Limit <String>] [-WhatIf [<SwitchParameter>]]
 Get-SPSite -SiteSubscription <SPSiteSubscriptionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Filter <ScriptBlock>] [-Limit <String>] [-WhatIf [<SwitchParameter>]]
 This example gets the collection of subweb titles in site collection at http://sitename.
Get-SPSite 'http://sitename' | Get-SPWeb -Limit All | Select Title
This example gets a subset of data from all of the sites in the content database b399a366-d899-4cff-8a9b-8c0594ee755f.
Get-SPSite -ContentDatabase "b399a366-d899-4cff-8a9b-8c0594ee755f" | Format-Table -Property Url, Owner, SecondaryOwner
My common usage:
List site sizes:
$site = Get-SPSite http://server/sites/site
$site.Usage.Storage / 1mb;
$site.Dispose();
 
 List Library sizes:
$site = Get-SPSite "http://server/sites/site";
$dataTable = $site.StorageManagementInformation(2,0x11,0,5);
$dataTable | ft Title, Size

Source: http://technet.microsoft.com/en-us/library/ff607950(v=office.14).aspx


Export-SPWeb

Exports a site, list, or library.

The Export-SPWeb cmdlet exports a site, list, or library. The capability to export from a library is a new feature in SharePoint 2010 Products.

Export-SPWeb [-Identity] <SPWebPipeBind> -Path <String> [-AssignmentCollection <SPAssignmentCollection>] [-CompressionSize <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-HaltOnError <SwitchParameter>] [-HaltOnWarning <SwitchParameter>] [-IncludeUserSecurity <SwitchParameter>] [-IncludeVersions <LastMajor | CurrentVersion | LastMajorAndMinor | All>] [-ItemUrl <String>] [-NoFileCompression <SwitchParameter>] [-NoLogFile <SwitchParameter>] [-UseSqlSnapshot <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
This example exports the site at http://site/ to a file called site export.cmp in the current directory.

Export-SPWeb http://server_name/sites/site_name –Path "site export.cmp"
My common usage:

Export-SPWeb -Identity http://server_name/sites/site_name -Path d:\import\im.cmp -IncludeUserSecurity -NoFileCompression -Verbose –Force
List sub-site sizes
function GetWebSizes ($StartWeb)
{
    $web = Get-SPWeb $StartWeb
    [long]$total = 0
    $total += GetWebSize -Web $web
    $total += GetSubWebSizes -Web $web
    $totalInMb = ($total/1024)/1024
    $totalInMb = "{0:N2}" -f $totalInMb
    $totalInGb = (($total/1024)/1024)/1024
    $totalInGb = "{0:N2}" -f $totalInGb
    write-host "Total size of all sites below" $StartWeb "is" $total "Bytes,"
    write-host "which is" $totalInMb "MB or" $totalInGb "GB"
    $web.Dispose()
}
function GetWebSize ($Web)
{
    [long]$subtotal = 0
    foreach ($folder in $Web.Folders)
    {
        $subtotal += GetFolderSize -Folder $folder
    }
    write-host "Site" $Web.Title "is" $subtotal "KB"
    return $subtotal
}
function GetSubWebSizes ($Web)
{
    [long]$subtotal = 0
    foreach ($subweb in $Web.GetSubwebsForCurrentUser())
    {
        [long]$webtotal = 0
        foreach ($folder in $subweb.Folders)
        {
            $webtotal += GetFolderSize -Folder $folder
        }
        write-host "Site" $subweb.Title "is" $webtotal "Bytes"
        $subtotal += $webtotal
        $subtotal += GetSubWebSizes -Web $subweb
    }
    return $subtotal
}
function GetFolderSize ($Folder)
{
    [long]$folderSize = 0 
    foreach ($file in $Folder.Files)
    {
        $folderSize += $file.Length;
    }
    foreach ($fd in $Folder.SubFolders)
    {
        $folderSize += GetFolderSize -Folder $fd
    }
    return $folderSize
}
GetWebSizes -StartWeb https://test-2010clientportal.cbre.com/sites/im



Restore-SPDeletedSite


Restores a deleted site collection.

Use the Restore-SPDeletedSite cmdlet to restore a previously deleted site collection.
Unlike the Restore-SPSite cmdlet that uses the host name and scheme for the Identity parameter (that is, http://server_name), the value of the identity parameter for all SPDeletedSite cmdlets use a server-relative URL. Typically, the forward slash character (/) begins the relative URL and also denotes the root site.
Restore-SPDeletedSite [-Identity] <SPDeletedSitePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-ContentDatabase <SPContentDatabasePipeBind>] [-WebApplication <SPWebApplicationPipeBind>] [-WhatIf [<SwitchParameter>]]
 This example restores a specific deleted site collection by using the site ID.

Restore-SPDeletedSite -Identity 610857cb-8414-4a89-8bf3-ad3628f6c86c
Source: http://technet.microsoft.com/en-us/library/hh286319(v=office.14).aspx


Import-SPWeb

Imports a web, list, or library.

The Import-SPWeb cmdlet imports a web, list, or library. The capability to import from a library is a new feature in SharePoint 2010 Products.

Import-SPWeb [-Identity] <SPWebPipeBind> -Path <String> [-ActivateSolutions <SwitchParameter>] [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-HaltOnError <SwitchParameter>] [-HaltOnWarning <SwitchParameter>] [-IncludeUserCustomAction <None | All>] [-IncludeUserSecurity <SwitchParameter>] [-NoFileCompression <SwitchParameter>] [-NoLogFile <SwitchParameter>] [-UpdateVersions <Append | Overwrite | Ignore>] [-WhatIf [<SwitchParameter>]]

This example imports the contents of export.cmp into a site at http://site, overwriting the versioned content on the site with the contents of the export.cmp file:

Import-SPWeb http://server_name/sites/site_name –Path export.cmp –UpdateVersions –Overwrite
My common usage:
Import-SPWeb -Identity http://server_name/sites/site_name -Path d:\Import\site.cmp -IncludeUserSecurity -NoFileCompression -Verbose –Force


Restore-SPSite

Restores a site collection.

The Restore-SPSite cmdlet performs a restoration of the site collection to a location specified by the Identity parameter. A content database may only contain one copy of a site collection. If a site collection is backed up and restored to a different URL location within the same Web application, an additional content database must be available to hold the restored copy of the site collection.

Restore-SPSite [-Identity] <String> -Path <String> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-ContentDatabase <SPContentDatabasePipeBind>] [-Force <SwitchParameter>] [-GradualDelete <SwitchParameter>] [-HostHeaderWebApplication <String>] [-WhatIf [<SwitchParameter>]]
Restore-SPSite [-Identity] <String> -Path <String> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-DatabaseName <String>] [-DatabaseServer <String>] [-Force <SwitchParameter>] [-GradualDelete <SwitchParameter>] [-HostHeaderWebApplication <String>] [-WhatIf [<SwitchParameter>]]
This example restores a site collection from the backup file C:\Backup\site_name.bak to the site collection URL http://server_name/sites/site_name.

Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak
This example restores a site collection backup from the backup file C:\Backup\site_name.bak, but overwrites the existing site collection at http://server_name/sites/site_name while specifying that the site collection must be stored in a specific content database.

Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak -Force -DatabaseServer SQLBE1 -DatabaseName SQLDB1
This example restores a site collection backup from the backup file \\file_server\share\site_name.bak to the host-named site collection http://www.example.com on the Web application http://server_name.

Restore-SPSite http://www.example.com -Path \\file_server\share\site_name.bak -HostHeaderWebApplication http://server_name
My common usage:

Restore-SPSite -Identity http://server_name/sites/site_name -Path d:\backup\im.bak -DatabaseServer <SQLServer> -DatabaseName WSS_Content_ClientPortal4_EXTProd -Force -Verbose


Move-SPSite

Moves site collections from one content database to another.

The Move-SPSite cmdlet moves the data in the specified site collection from its current content database to the content database specified by the DestinationDatabase parameter.

Move-SPSite [-Identity] <SPSitePipeBind> -DestinationDatabase <SPContentDatabasePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-RbsProviderMapping <Hashtable>] [-WhatIf [<SwitchParameter>]]
This example moves the site collection http://servername/sites/sitename to the content database ContentDb2.

Move-SPSite http://servername/sites/sitename -DestinationDatabase ContentDb2
This example moves all site collections in ContentDb1 to ContentDb2.

Get-SPSite -ContentDatabase ContentDb1 | Move-SPSite -DestinationDatabase ContentDb2
This example moves all site collections where DOMAIN\username is the site collection owner to ContentDb2. The Get-SPSiteAdministration cmdlet is used instead of the Get-SPSite cmdlet because you must have permission within the site collection to access the properties of the SPSite object. You can access the properties of the SPSiteAdministration object as a SharePoint farm administrator.

Get-SPSiteAdministration | where { $_.OwnerLoginName -eq "DOMAIN\username" } | Move-SPSite -DestinationDatabase ContentDb2
My common usage:

Move-SPSite https://clientportal.cbre.com/Sites/IM -DestinationDatabase WSS_Content_ClientPortal11-EXT
 Source: http://technet.microsoft.com/en-us/library/ff607915.aspx



Get-SPDatabase

Retrieves all properties of a database.

The Get-SPDatabase cmdlet displays all public properties of a database to the current window. If the Identity parameter is specified, only properties of that ID are displayed.

 Get-SPDatabase [[-Identity] <SPDatabasePipeBind>] [-AssignmentCollection <SPAssignmentCollection>]

Get-SPDatabase -ServerInstance <SPDatabaseServiceInstancePipeBind> [-AssignmentCollection <SPAssignmentCollection>]
This example gets all databases on a specific named SQL Server Express instance.

Get-SPDatabase –ServerInstance "ServerA\SharePoint"
My common usage:
Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name, @{Label ="Size in MB"; Expression = {$_.disksizerequired/1024/1024}}
Source: http://technet.microsoft.com/en-us/library/ff607889(v=office.14).aspx



Get-SPUser

Returns the user account or accounts that match a given search criteria.

The Get-SPUser cmdlet returns all SharePoint user accounts that match the scope given by the Identity, Web, or Group parameters.
Get-SPUser [[-Identity] <SPUserPipeBind>] -Web <SPWebPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Group <SPGroupPipeBind>] [-Limit <String>]
This example returns all members of the group Viewers on the Web site http://zsharepoint2.
Get-SPUser -Web "http://zsharepoint2" -Group "Viewers"
Source: http://technet.microsoft.com/en-us/library/ff607580(v=office.14).aspx

Wednesday, January 30, 2013

Ultimate Experience Promotion


Ultimate Experience Promotion

For those of you that may be interested in taking your ideas into the app store, Microsoft is providing some help and promotions below.  Check it out:

To help with your Windows 8 app certification process, we’re gathering the top Microsoft Evangelists to give you “Top Tips” to speed your app through the certification process and submitting it to the Windows Store.

Join us for this 1 hour webcast on February 19, 2013 at 4:00 pm PST. To register visit,
https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032539563&culture=en-US

Developers who publish one or more apps to the Windows Store or the Windows Phone Store by 5pm PT, Feb 28th 2013 are eligible to receive reimbursement for their Store Registration fees and will be entered to win one of 12 Xbox 360 Consoles with Kinect. Three lucky developers will win a trip for 2 to Redmond to spend a day with the members of the Windows 8 Games Studios team, participate in coding and get a sneak peak at an upcoming game!

Join Generation App and we'll help you meet the people who have the skills to build Windows 8 apps.



KnowledgeLake Capture: SharePoint ECM for the iPhone and iPod Touch

Check out the KnowledgeLake Capture App for iPhone/iPad


https://www.youtube.com/watch?v=Wr3Q1QmBIP4

Friday, January 25, 2013

PowerPivot - Unable to Refresh



SharePoint 2010 SP1 - SQL 2008 R2 - PowerPivot


I ran across an issue where I was unable to refresh the data in a data slicer. I was receiving the error:


Unable to refresh data for a data connection in the workbook. Try again or contact your system administrator. The following connections failed to refresh: PowerPivot Data 

As it turned out, the account for Claims to Windows Token Service (C2WTS) was set as a domain account.

C2WTS can be set to a domain account, but Kerberos constrained delegation must be configured, as well as the local login policy for that domain account.
The account must be a Local Administrator.  The account must have the following rights in the Local Security Policy User Rights Assignment: Act as part of the operating system; Impersonate a client after authentication; Logon as a service.
Alternatively, the C2WTS account can be set to local system account. - Which is the solution I deployed.


Tuesday, January 22, 2013

SharePoint 2013 On Premise/Cloud Hybrid Environment



Excerpted from Christopher J Fox's technet blog post: http://blogs.technet.com/b/tothesharepoint/archive/2012/11/09/introducing-the-sharepoint-hybrid-configuration-scenario.aspx

A SharePoint 2013 hybrid environment consists of an on-premises SharePoint 2013 farm and a tenancy in the new SharePoint Online.  The integration of the two allows you to use certain resources from the two constituent environments to build unified solutions.  These solutions then run seamlessly across the two.
A SharePoint 2013 hybrid environment supports these features:

  • Search
  • Business Connectivity Services from SharePoint Online to SharePoint on-premises

As of the SharePoint Conference 2012, you can find information on SharePoint Hybrid Environments and links to downloadable white papers and poster here on TechNet.
Hybrid content for the SharePoint Conference 2012

  • Configure a SharePoint 2013 Hybrid Environment -  A whitepaper  that describes how to configure a hybrid environment that integrates SharePoint Server 2013 and Office 365 with single sign-on, identity management, and bi-directional federated Search
  • SharePoint 2013 Business Connectivity Services Hybrid Overview – This document explains what a BCS Hybrid environment is and why you would use it.  It identifies the components that are involved and explains their roles in the solution.  It also walks you through how a BCS Hybrid solution works.
  • SharePoint 2013 Business Connectivity Services Hybrid Poster – A full size poster that explains the flow of data and authentication in a BCS Hybrid environment.




Thursday, January 17, 2013

Send Notification On Workflow Errors

Many of my clients have OOTB workflows enabled on their SharePoint farm(s). This will allow users to create and manage their own, simple workflows. However, one problem I have encountered is the support for those workflows tend to end with the creation of the workflow. 

One issue with user-implemented/supported workflows is notification when workflows fail. One of my client's requested a notification of failing workflows. My initial thought was to create another workflow to monitor and send notifications when user workflows entered into an error state. Then, I remembered SharePoint offers OOTB alerting..so, I decided to check with the SharePoint community to see if there were any good, ootb solutions for notifying upon failure. I eventually came across Dave Sampson's post regarding his solution and voila! Simple, yet very effective solution! Check out his solution located on his blog http://dave-sampson.blogspot.com/2012/06/simple-sharepoint-2010-workflow-error.html

Print Calendar and/or Lists

Have you ever had the need to print a day's activity from a SharePoint calendar, or any other list/library, in an easy to read format?

There are a few options to accomplish this task (I will cover just a few).
  • Create a new list view - good for a single calendar (does not scale well - requires creating a new view for each calendar)
  • Add a new feature providing a print ability for every list/library from the 'Actions' > 'Print' menu. http://www.spelements.com/spelements.com/spprint
  • If it is a single list/library/calendar AND you are using Outlook, you can import the list/library/calendar into Outlook and print the same format as Outlook calendars:
    • Open SharePoint Calendar in Outlook

      1. Open the calendar that you want to print on the SharePoint website.
      2. Click "Connect to Outlook" in the "Actions" group on the "Calendar" tab.
      3. Click "Allow" to confirm that you want to allow the SharePoint website to open Outlook on your computer. Outlook automatically opens.
      4. Click "Yes" to confirm that you want the SharePoint calendar to connect to Outlook. The SharePoint calendar automatically appears in Outlook under "Other Calendars."

    • Print the SharePoint Calendar

      1. Click "Other Calendars" in the navigation pane in the left side of the window. Click the SharePoint calendar to open it.
      2. Click the "File" tab in Microsoft Outlook, then click "Print."
      3. Select "Calendar Details" style under "Print What" to print the complete details of the SharePoint calendar.
      4. Click "Print Options" to select print options such as the date range or printing a specific page. Click "Print" after selecting your options to print the SharePoint calendar.

Wednesday, January 16, 2013

Resolving Event ID 7043: ‘Load control template file /_controltemplates/TaxonomyPicker.ascx failed


Event ID 7043: ‘Load control template file /_controltemplates/TaxonomyPicker.ascx failed: Could not load type 'Microsoft.SharePoint.Portal.WebControls.TaxonomyPicker' from assembly Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.

This error is a result of the control “TaxonomyPicker.ascx” not actually required – it was left in accidentally from release. When SharePoint websites start they automatically compile and cache controls in the “/_controltemplates” folder (default location is C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES), which includes the TaxonomyPicker.ascx control. The controls are checked against the SharePoint DLLs (Microsoft.SharePoint.Portal in particular), and thus the error that is raised is actually because the control entry does not exist in the SharePoint DLLs. Hence the event log is actually saying “I have an .ascx file that does not have a matching entry in the SharePoint DLLs”.

The Microsoft supported fix is to modify the ascx file and replace a few characters with a ‘,’. Additional research revealed, from numerous posts, the solution from Microsoft did not work for most. Instead, most, if not all, of the postsmentioned simply renaming this file (specifically the extension) to resolve. Something along the lines of TaxonomyPicker.ascx -> TaxonomyPicker.ascx.old or some derivative there-of.

Friday, January 11, 2013

Invalid Application Path Error in IIS 7.5 Pass-Through Authentication

IIS > SharePoint Web Services > (applicaiton) > Basic Settings > Test Settings

Results in an Invalid Application Path error message.

When The server is configured to use pass-through authentication with a built-in account to access the specified physical path. However, IIS Manager cannot verify whether the built-in account has access.
You see this error message (actually it is a warning message) because you have choose to use pass-through authentication. In this situation, the application pool is run under a low-privileged built-in account, usually Network Service, or ApplicationPoolIdentity. IIS cannot verify that the built-in account has proper settings, this can only be done at run-time.
In addition to this, the "Test Settings" process does not know which user you have authenticated as. So basically, you need to verify that the application pool identity has read access to the files and configuration files. You also need to make sure that the application identity has proper security settings.
So in most situations, you can safely ignore the warning message, because on a default setup, all the permission settings are correct.

Wednesday, January 9, 2013

System Center Monitoring Pack for SharePoint 2013

Key Updates in System Center Monitoring Pack for SharePoint 2013

System Center Monitoring Packs (previously known as Management Packs), for both SharePoint Server 2013 and SharePoint Foundation 2013, were released on November 8, 2012. You can download them at the download center:




  1. 102 new monitors/rules are added for better monitoring of new services and existing ones in SharePoint 2013:
    • Added monitoring for brand new services in SharePoint 2013, such as Education and Translation. Also added monitoring to newly added services of Access and Search in SharePoint 2013.
    • Enhanced monitoring for existing services, such as Project, Usage database and Visio.
  2. Redesigned SharePoint Monitoring Pack architecture for easier development and upgrade.
    • Componentized into Library (SharePoint version common), Discovery and Monitoring (SharePoint version specific).
    • Easier management pack development and upgrade in the future
      • Users can reuse the common Class in Library to add their new monitors and rules without impact on the existing ones.
      • Users’ own monitors and rules can be upgraded to the future SharePoint version without change (the Library is common for SharePoint versions).

New Microsoft SharePoint Certification for SP 2013

Check out the latest SharePoint certification (and it's not a Microsoft Certified Systems Engineer: Microsoft Certified Solutions Expert

SP 2013 - Introducing the Content Search Web Part


Have you ever wanted to display content on a page from another site collection and been unsuccessful in finding an out of the box solution? Those days are now gone!

Microsoft has included a new web part called Content Search. With the tight integration of SharePoint Search and FAST for SharePoint Search in SharePoint 2013, Microsoft added the Content Search Web Part to address the issue of not being able to cross site collections for the content aggregation. In fact, the Content Search Web Part will display all content available in the search index, regardless if it is SharePoint content or not! (As long as viewers have read rights to the content)

The Content Search Web Part can be found in the Content Roll-up category of the Web Part Gallery. (Content Search is not available on Office 365 right now, but we are working on enabling it in the future.)

Reference - Content Search Web Part