Extracting Solution Packages (WSPs) from SharePoint using PowerShell

I just stumbled across this link from Kirk Evanshttp://blogs.msdn.com/b/kaevans/archive/2011/12/05/extract-a-wsp-solution-from-sharepoint-2010.aspx

Basically, using 3 lines of PowerShell (which can be turned really into one if needed), to extract a SharePoint Solution Package (WSP) from the Farm Solutions collection.

From his post:

$farm = Get-SPFarm

$file = $farm.Solutions.Item("extendeddiagnosticproviders.wsp").SolutionFile

$file.SaveAs("c:\temp\extendeddiagnosticproviders.wsp")

As awesome as it is easy.

Advertisement

How much storage space is my site collection using?

NOTE: This post is just covering SharePoint 2010, and not earlier versions of the product.

imageA common question administrators have in their SharePoint environment is “How much storage space is my site collection using?”

Well, fear not, trusty SharePoint administrators! There are a few ways to skin this cat – and we’re going to take a look at them.

 

SharePoint Designer

SharePoint Designer – what was once something administrators and power users shuddered at the mere mention of the tool in prior versions of the product, has gotten a makeover. And, also has a lot of additional functionality. For today’s lesson however, we are only going to look at one specific feature of it – the ability to view the storage used for an entire site collection!

If you open up SharePoint Designer to the root site of your site collection, in the main window, once the site is opened under Site Information, you will see, as highlighted below, that it will conveniently display the Total Storage Used of your entire site collection! There! As the big red button on my desk often says after a good firm press… “That was easy!”.

image

Let’s look at a couple of other methods of getting this information, shall we?

StorMan.aspx – SharePoint 2010 Service Pack 1+

This one requires Service Pack 1 to be installed to be able to utilize this feature. It was not in the RTM version. At the root of your site collection, if you go to Site Actions > Site Settings > Site Collection Administration > Storage Metrics, this will give you details on the usage – such as what sites, lists, libraries, and items are taking up the most space, however, it will not give you a total like our trusty SharePoint Swiss Army Knife – SharePoint Designer does, but, it will allow you to drill down into the usage.

image

I will also urge you to view Bill Baer’s article on Storage Metrics in Service Pack 1 – which has some great screenshots of the functionality, as well as an overview, available here: http://blogs.technet.com/b/wbaer/archive/2011/06/28/service-pack-1-storage-metrics-storman-aspx.aspx

PowerShell

imagePowerShell, one of the other power tools in SharePoint 2010, much more akin to the Ginsu knife, can also serve up the details, and, like the Ginsu knife, allow you to slice and dice the information in a myriad of ways.

Below is an example script to connect to your site collection, and read out all of the usage information.

$site = Get-SPSite http://my.sitecollection.com
$site.Usage;
$site.Dispose();

Which gives the following output (storage shown highlighted below in bytes):

image

To view just the Storage property, and not Bandwidth, Visits, Hits, and DiscussionStorage, you can call this:

$site = Get-SPSite http://my.sitecollection.com
$site.Usage.Storage;
$site.Dispose();

And only the Storage property with the total bytes will be displayed. You can also do some other cool tricks, such as calculating kilobytes, megabytes, gigabytes and terabytes right from the command line as well, to make the results a bit more readable:

image

Want more? OK! We can give it to you! Keep reading! (Because, reading is fundamental, you know.)

Web Analytics

Another option to view the storage used, as well as some additional metrics around it, if you have Web Analytics enabled, you can view your usage over time. To see this, go to Site Actions > Site Settings > Site Actions > Site Collection Web Analytics reports

image

Once there, in the main screen, you can view a summary of the Total Storage Used under Inventory.

image

And if you click on Storage Usage under Inventory within the quick launch navigation on the left, you can then view reports on storage utilization for your site collection, with a graph of the values so you cane easily visualize the trend in storage usage.

image

image

As well as a daily breakdown of the storage used, so you can see how this grows or falls over time.

image

You can also run reports for any date range since Web Analytics have been enabled, as well as run workflows against this data for alerting and reporting.

image

I hope you were able to learn something new today… have another method in which you get your site collection storage metrics? Leave it in the comments below for everyone else!

Generic Errors with Lists and Manage Content and Structure Tool

image

An unexpected error has occurred. Yep. Very helpful! Recently, when attempting to use the Manage Content and Structure tool (found under Site Actions > Manage Content and Structure), I received the above error. Looking into the ULS logs, all I was able to get ahold of was a System.NullReferenceException. Again, not really handy, or useful, at all.

I was able to determine that it had to probably be due to a list… turns out, we had deactivated and retracted several features from our farm recently, several of which relied on custom lists to store the data. If I go to View All Site Content (Site Actions > View All Site Content), and click on one of these lists, I get a similar error to the above.

Luckily, one of the times when attempting to launch the Manage Content and Structure Tool, I was able to get this error in the ULS logs.

Failed to determine the setup path of the list schema for feature {553B9E4F-C7EA-4442-845F-94390C1EAE44}, list template 10000.

So, basically, we need to remove these lists. We cannot get into the “Delete this List” option within the List management screen – otherwise you’ll get an error similar to the above. I also attempted to use SharePoint Manager 2010, which also gave an error. I just couldn’t delete the list using traditional means…

You have two options here…

  1. Write some code to delete the list (C#, PowerShell… whatever you desire)
  2. Use Gary LaPointe’s STSADM extensions and PowerShell scripts.
    1. Remove-SPList PowerShell Command
    2. gl-deletelist STSADM command

Either of those should do the trick! Now, to get the List URL is simple, the lists should still appear under View All Site Content, just right-click and copy the shortcut to the list view, for example: http://sharepointsite.com/Lists/SomeCustomList/AllItems.aspx

Use that when calling those commands with the URL parameter, and you’re good to go.

PowerShell script to list all Webs and Site Templates in use within a Site Collection

And one more quick post today, this PowerShell script will iterate through all Webs within a Site Collection, print out their Title, URL, and WebTemplate (Site Template) name.

   1: $site = Get-SPSite "http://yoursite"

   2: foreach ($web in $site.AllWebs) { 

   3:     $web | Select-Object -Property Title,Url,WebTemplate 

   4: }

   5: $site.Dispose()

And again, before you use this – please read this: https://gvaro.wordpress.com/2011/03/26/test-out-your-powershell-scripts-first-in-a-non-production-environment-first/ (and also read the comment by Anders Rask)

LotD: Using PowerShell to Approve List Items

The Link of the Day (LotD) goes out to Eric Shupps for this quick PowerShell snippet http://www.binarywave.com/blogs/eshupps/Lists/Posts/Post.aspx?List=89cbe813%2D99f7%2D4257%2Da23a%2D5fefc377336b&ID=241&Web=c7893495%2Dbe3b%2D4d73%2D9875%2D28b039760651. This PowerShell code will loop through a list of your choice and approve list items. This is a huge timesaver for me right at the moment. Thank you Shupps!

I do have some slight changes to the code. There is no need to open the site collection object (line 1), we can just use Get-SPWeb to open the web we need, and, also disposing of the web object at the end, so we don’t leave it sitting around eating up memory on the server.

Normally I do not create posts like this, but, I think I had something to add to it, and, I know exactly where to find it later on, as I am sure I will need it.

   1: $web = Get-SPWeb "http://site"

   2: $list = $web.Lists["Posts"]

   3: $items = $list.Items 

   4:  

   5: foreach ($item in $items)

   6: {

   7:     $item["_ModerationStatus"] = 0

   8:     $item.Update()

   9: } 

  10: $web.Dispose()

And before you use this – please read this: https://gvaro.wordpress.com/2011/03/26/test-out-your-powershell-scripts-first-in-a-non-production-environment-first/ (and also read the comment by Anders Rask)

TEST OUT YOUR POWERSHELL SCRIPTS FIRST IN A NON-PRODUCTION ENVIRONMENT FIRST

You may be wondering why I applied such bad grammar to the title of this post, it came from a comment on this: https://www.nothingbutsharepoint.com/sites/itpro/Pages/Seven-Virtues-for-the-SharePoint-IT-Pro.aspx

PowerShell is a beast. Sure, it’s hard to learn the syntax, and there are 600+ commands that come along with SharePoint 2010. But, it also gives you direct access to the API for SharePoint. Never, ever, ever, ever, ever, ever, ever, ever, ever, ever, ever, ever, ever, ever, ever, under any circumstances what-so-ever, run un-tested PowerShell code in a production environment. ever. ever. ever. ever. ever. ever. ever. ever. ever. ever. ever. ever. ever. ever. ever.

What may have worked for one person, in which they have posted it on their blog, mailing list, or company-wide fax – it should be tested first, in a non-production environment.

It may work fine, sure, but, it may also grind everything to a halt, and end your career.

In closing, re-read the above, and make it your mantra. No go fourth, SharePoint admins (and devs – yes you too), and prosper.

Delete a master page in SharePoint using PowerShell

Had one of my group approach me today inquiring about deleting a master page from a site collection using PowerShell. Quick and simple way to do it…

 

   1: $web = Get-SPWeb "http://prototype"

   2: $lib = $web.GetFolder("_catalogs/masterpage")

   3: $file = $lib.Files["v4_copy(1).master"];

   4: $file.Delete();

   5: $web.dispose();

 

So I thought I would share. Enjoy!

Microsoft.BusinessData.Runtime.ExceededLimitException: Database Connector has throttled the response.

If you’ve created a BCS list before (such as defined by the excellent tutorial put together by Laura Rogers for connecting to a SQL data source using a SQL account – http://www.sharepoint911.com/blogs/laura/Lists/Posts/Post.aspx?ID=90), and received this error on your Read List view page:

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Microsoft SharePoint Foundation-compatible HTML editor such as Microsoft SharePoint Designer. If the problem persists, contact your Web server administrator.

Correlation ID:117e242f-0985-42e9-9972-b1a879ce7e3b

After investigating the ULS Logs, located in %SYSTEM DIR%\Program Files\Common Files\Microsoft Shared\web server extensions\14\LOGS, and searching for the correlation id mentioned above. You may find the following error:

Error while executing web part: Microsoft.BusinessData.Runtime.ExceededLimitException: Database Connector has throttled the response. The response from database contains more than ‘2000’ rows. The maximum number of rows that can be read through Database Connector is ‘2000’. The limit can be changed via the ‘Set-SPBusinessDataCatalogThrottleConfig’ cmdlet.     at Microsoft.SharePoint.BusinessData.SystemSpecific.Db.ThrottledIDataReader.Read()     at Microsoft.SharePoint.BusinessData.SystemSpecific.Db.DbEntityInstanceEnumerator.MoveNext()     at Microsoft.SharePoint.BusinessData.Runtime.EntityInstanceEnumeratorBase.MoveNext()     at Microsoft.SharePoint.SPListDataSource.GetFilteredEntityInstancesInternal(XmlDocument xdQueryView, Boolean fFormatDates, Boolean fUTCToLocal, String firstRowId, Bo…

Thanks to the wonders of the interwebs, the solution to this is fairly simple, and the error explanation is extremely helpful. Do a search for this: Set-SPBusinessDataCatalogThrottleConfig, which will lead you to a great article on the Microsoft Business Connectivity Services Team Blog by Adam Outcalt here: http://blogs.msdn.com/b/bcs/archive/2010/02/16/bcs-powershell-introduction-and-throttle-management.aspx which will give you very great instructions on modifying the BCS throttling configuration.

Be careful with this however, the throttling is there for a reason. Not just to give you another option to configure.

SharePoint & PowerShell 101: Finding Cmdlets

imageI recently did a post on Listing all available PowerShell commands in SharePoint 2010. That is all well and good, if you want to manually browse through all of them. But what if you want to search for them?

 

Get-Command

Get-Command is a highly useful cmdlet in PowerShell. Today we are just going to use a basic functionality of it, to help us find and locate the cmdlets we need to use. Today, we need to do some work with the User Profile Service. However, we don’t know what the command names are that we need to use, only that we need to use them. For that, we can use Get-Command. If you need to figure out how to use the Get-Command cmdlet, run

Get-Help Get-Command

Which will return the following information about the cmdlet

image

This will return the usage of the Get-Command cmdlet. We are just going to use the –Noun switch to pass in our parameters.

Let’s start looking at the basics… we’re looking to find commands relating to the User Profile Service. So, let’s try searching for a noun of Profile

Get-Command –Noun Profile

Nothing is returned… oh right, it would appear that the Get-Command is literal, not a wildcard. However, we can use a wildcard character to help us search, as we have no idea what the name of the command is. Let’s try searching for *Profile*, that should do the trick.

Get-Command –Noun *Profile*

image

Hooray, results! However, we cannot see the entire name of the results returned. For that, we can use the Select-Object cmdlet.

Fore information on using that, try this in the PowerShell console

Get-Help Select-Object

So, let’s only pull the Name property in our results of the Get-Command

Get-Command -Noun *Profile* | Select-Object –Property Name

image

Much better! We can further refine these by adjusting our Noun, to just look at ProfileService

Get-Command -Noun *ProfileService* | Select-Object -Property Name

image

And there we go! Hopefully this helps you in your quest to add PowerShell to your arsenal of SharePoint management and development tools.

I’d love to hear what else you would like to learn about – leave me information in the comments!

Deploying and Activating Features in SharePoint 2010 with PowerShell

I was looking at an article on MSDN blogs today for customizing My Sites in SharePoint 2010. This post is not about that, but rather PowerShell that were there for deploying and activating a feature. Here is the text, direct from the site itself. This installs a feature (a), enables the feature (b), and then activates the feature on each site (c).

a.       Install-SPFeature -path "MyNewNavFeature"
b.       Enable-SPFeature -identity "MyNewNavFeature" -URL http://<mysitehost&gt; (Enables the new feature on the mysitehost)
c.       Enable the new feature on all personal sites:

$personalSites = get-spsite | where {$_.RootWeb.WebTemplate -eq "SPSPERS"}
foreach ($site in $personalSites) {Enable-SPFeature -Identity "MyNewNavFeature" -Url $site.Url}

 

The blog posting – where credit is due: http://blogs.msdn.com/b/spsocial/archive/2010/04/08/customizing-my-sites-in-microsoft-sharepoint-2010.aspx

%d bloggers like this: