Archive | PowerShell RSS for this section

Use PowerShell to quickly show your SharePoint Features

I wanted to know what features were installed on my farm. Not just farm-scoped features, but all feature scopes. So I wrote some quick powershell to tackle the job.

Here is a screenshot of the code for easier reading.

Alt text for the script

Script to display all SharePoint features

Here is the code so that you can copy/paste.

Add-PSSnapin Microsoft.SharePoint.Powershell
write-host "Farm scoped features"

# This will display all Farm scoped features
#Get-SPFeature -Farm 

# This will display a specific Farm scoped feature if it exists
Get-SPFeature -Farm | where { $_.Id -eq "319d8f70-eb3a-4b44-9c79-2087a87799d6" }


foreach ($webapp in get-spwebapplication) {

  write-host "Web Application " $webapp.url  

  # All WebApplication scoped features
  #Get-SPFeature -WebApplication $webapp.url 

  # specific WebApplication scoped feature if it exists
  Get-SPFeature -WebApplication $webapp.url | where { $_.Id -eq "0ea1c3b6-6ac0-44aa-9f3f-05e8dbe6d70b" }

  foreach ($site in $webapp.sites) {

    write-host "Site Collection " $site.url 

    # All SiteCollection scoped features
    #Get-SPFeature -Site $site.url 

    #specific SiteCollection scoped feature if it exists
    Get-SPFeature -Site $site.url | where { $_.Id -eq "7094bd89-2cfe-490a-8c7e-fbace37b4a34" }


    foreach ($web in $site.AllWebs) {

      write-host "Web " $web.url 

      # All Web scoped features
      #Get-SPFeature -Web $web 

      # Specific web scoped feature if it exists
      Get-SPFeature -Web $web | where { $_.Id -eq "00bfea71-1e1d-4562-b56a-f05371bb0115" }

write-host "Done"

STSADM to PowerShell mapping

For those joining me in learning powershell for SharePoint, here is a handy reference on technet mapping the ststadm commands to PowerShell commands.

Use PowerShell to Get ManagedPaths in SharePoint 2010

Just a quick post here. I wanted to get a list of all Managed Paths in my SharePoint 2010 farm.

So I first saw


Next, I found it’s parameters by using

get-help get-spmanagedpath

Note: If you use it without a parameter, it prompts you for the web app url. Kind of neat. The PowerShell ISE actually displays a dialog window, while the PS> cmd prompt asks for a parameter.

Knowing that I could get a list of web applications from somewhere, I found


And then piping each webapplication’s “url” property to another commandlet will get me what I’d like. And that is a listing of all managed paths in my farm.

get-spwebapplication | foreach { Get-SPManagedPath -WebApplication $_.url }

From there, it was all playing with the script to save both the web application url and the managed path. Here’s what I came up with:

And here is the code if you need to copy and paste it.

write-host "------ BEGIN -----"
write-host ""
Add-PSSnapin Microsoft.SharePoint.Powershell
$a = New-Object System.Collections.ArrayList
$webapps = get-spwebapplication
foreach ($webapp in $webapps)
    $paths = Get-SPManagedPath -WebApplication $webapp.url;
    foreach ($path in $paths)
        $a.Add( $webapp.url + $ );
#Write out the results if you need them
write-host ""
write-host "------ END -----"

Next stop, creating a managed path with PowerShell.

My PowerShell ISE WishList

This will probably be a Part I of several. As the SharePoint community becomes more versed in PowerShell, the more folks are going to demand of it, and the ISE (Integrated Scripting Environment). Here are some features I wish Microsoft had incorporated into the PowerShell ISE.

1. Find in Files (from Visual Studio)

2. Projects (from SSMS, SQL Server Management Studio)

Get a SharePoint Site Collection Storage List for PowerShell

I wanted to see the breakdown of my site collections’ size. And this one’s pretty easy.

Here’s the command I used:

 foreach ( $site in get-spsite ) {
write-host $site.url -  $ }

Here’s the output:

SharePoint Listing of all Lists in a Farm or a Site Collection using PowerShell

Here’s how you can view all the lists within a farm, even hidden lists like the TaxonomyHiddenList. Now, if you have a large farm, you obviously aren’t going to display all lists. You may, however, still want to display all lists in a site collection. That’s covered at the end of the post.

PS> foreach ($site in get-spsite) { 
foreach ($web in $site.AllWebs) { 
foreach ($list in $web.lists) 
{write-host $site.url - $web.Title - $list.Title 
} } } 

Great. Now let’s get something more. But what? What do we have to choose from? Well, here’s how to find that out.

And our output should look something like this:

You can run these 2 commands. The first stores all site objects into memory. The second then uses that memory to get the members of objects in memory.

PS C:\Users\david.frette> $sitelists = foreach ($site in get-spsite) {
 foreach ($web in $site.AllWebs) { 
foreach ($list in $web.lists) { 
$list } } }
PS C:\Users\david.frette> $sitelists | get-member

Then you’ll get this output! (Screen shots truncated)

What we see are the members of two different objects, the SPList and the SPDocumentLibrary.

Let’s choose a report that displays the Title, Hidden, and ItemCount. Our statement should look something like:

PS C:\Users\david.frette> $sitelists | select Title, Hidden, ItemCount

So that’s it in a nutshell: a quick listing of all lists in a farm. Now, if you just want a listing of all lists in a site, here’s what you want. Three commands.
The first sets a reference to your specific site collection.
The second places each list into memory (sitelist variable).
The third displays a report.

PS C:\Users\david.frette> 
$site = new-object Microsoft.SharePoint.SPSite("http://demo9/sites/BI")

PS C:\Users\david.frette> 
$sitelists =  foreach ($web in $site.AllWebs) { 
foreach ($list in $web.lists) { $list } }

PS C:\Users\david.frette> 
$sitelists | select Title, Hidden, ItemCount