David Frette's Blog

Where the mind and SharePoint sometimes meet.

Archive for the ‘PowerShell’ Category

Use PowerShell to quickly show your SharePoint Features

Posted by David Frette on December 30, 2010

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.

clear-host;
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" }

write-host 

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" }
  write-host 

  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" }

    write-host 

    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
    }
  }
}
write-host "Done"

Posted in PowerShell, SharePoint | Leave a Comment »

STSADM to PowerShell mapping

Posted by David Frette on May 2, 2010

http://technet.microsoft.com/en-us/library/ff621081(office.14).aspx

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

Posted in PowerShell, SharePoint | Leave a Comment »

Use PowerShell to Get ManagedPaths in SharePoint 2010

Posted by David Frette on April 24, 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

Get-SPManagedPath

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

get-spwebapplication

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.

clear-host
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 + $path.name );
    }
}
#Write out the results if you need them
$a
write-host ""
write-host "------ END -----"

Next stop, creating a managed path with PowerShell.

Posted in PowerShell, SharePoint | Leave a Comment »

My PowerShell ISE WishList

Posted by David Frette on March 30, 2010

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)

Posted in PowerShell | Tagged: | 2 Comments »

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

Posted by David Frette on March 12, 2010

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

Posted in PowerShell, SharePoint | Leave a Comment »

How to determine PowerShell Version

Posted by David Frette on March 11, 2010

I wanted to check my PowerShell version information. Perhaps I’ll need to do so in future scripts. Here’s how to determine the PowerShell Version from within PowerShell.

PS C:\Users\david.frette> $host.version

Major Minor Build Revision
—– —– —– ——–
2 0 -1 -1

PS C:\Users\david.frette> $host.version.major
2
PS C:\Users\david.frette> $host.version.minor
0
PS C:\Users\david.frette> $host.version.build
-1
PS C:\Users\david.frette> $host.version.revision
-1

Posted in PowerShell, SharePoint, Uncategorized | 4 Comments »

 
Follow

Get every new post delivered to your Inbox.