Get all SharePoint lists by using PowerShell

My last article explained how you can retrieve all your workflows from your SharePoint 2010 farm. After this, I got some requests from people that wanted an overview of all their used lists in SharePoint 2010.

For this, I adjusted my last script a little to output all your SharePoint lists and libraries. Or you can specify the -URL parameter to get just the lists from the particular site.

param
(
[string] $URL,
[boolean] $WriteToFile = $true
)

#Get all lists in farm
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Counter variables
$webcount = 0
$listcount = 0

if($WriteToFile -eq $true)
{
$outputPath = Read-Host "Outputpath (e.g. C:\directory\filename.txt)"
}
if(!$URL)
{
#Grab all webs
$webs = (Get-SPSite -limit all | Get-SPWeb -Limit all -ErrorAction SilentlyContinue)
}
else
{
$webs = Get-SPWeb $URL
}
if($webs.count -ge 1 -OR $webs.count -eq $null)
{
    foreach($web in $webs)
    {
   #Grab all lists in the current web
    $lists = $web.Lists   
    Write-Host "Website"$web.url -ForegroundColor Green 
    if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value "Website $($web.url)"}
        foreach($list in $lists)
        {
            $listcount +=1  
            Write-Host " – "$list.Title          
            if($WriteToFile -eq $true){Add-Content -Path $outputPath -Value " – $($list.Title)"}
        }
    $webcount +=1
    $web.Dispose()
    }
#Show total counter for checked webs & lists
Write-Host "Amount of webs checked:"$webcount
Write-Host "Amount of lists:"$listcount
}
else
{
Write-Host "No webs retrieved, please check your permissions" -ForegroundColor Red -BackgroundColor Black
}

You can run the script by running the .ps1 file. There are 2 parameters that you can add.

WriteToFile: Default is true. If the parameter is set to true, the console will ask for a output location where the text file will be saved.
URL: Default is empty. If the URL Parameter is set, only the web you specified and all webs under this web will be reported.

Here is a possible outcome:

image

Advertisements

Get all workflows in all sites and lists

From an administrator point of view, it can be hard to keep track of all workflows used in your SharePoint 2010 environment. To make things a little easier, I created a script that will tell you the names of all workflows that are used within your SharePoint farm.

Please make sure that the user running this script has at least read permissions to the webs you are trying to check.

*UPDATE* Version 1.1 *UPDATE*
– Increased performance by using the .allwebs property instead of Get-SPWeb
– Changed the script so you can run the script as any other PowerShell script

param ([boolean] $writeToFile = $true)
#List all workflows in farm
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #If boolean is set to true, you can specify an outputlocation, to save to textfile.

if($writeToFile -eq $true)
{
$outputPath = Read-Host "Outputpath (e.g. C:\directory\filename.txt)"
}
#Counter variables
$webcount = 0
$listcount = 0
$associationcount = 0

#Grab all webs
Get-SPSite -Limit All | % {$webs += $_.Allwebs}
if($webs.count -ge 1)
{
foreach($web in $webs)
{
#Grab all lists in the current web
$lists = $web.Lists
foreach($list in $lists)
{
$associations = @()
#Get all workflows that are associated with the current list
foreach($listassociation in $list.WorkflowAssociations)
{
$associations += $($listassociation.name)
}
$listcount +=1
if($associations.count -ge 1)
{
Write-Host "Website"$web.url -ForegroundColor Green
Write-Host "  List:"$list.Title -ForegroundColor Yellow
foreach($association in $associations){Write-Host "   -"$association}

if($WriteToFile -eq $true)
{
Add-Content -Path $outputPath -Value "Website $($web.url)"
Add-Content -Path $outputPath -Value "  List: $($list.Title)"
foreach($association in $associations){Add-Content -Path $outputPath -Value "   -$association"}
Add-Content -Path $outputPath -Value "`n"
}
}
}
$webcount +=1
$web.Dispose()
}
#Show total counter for checked webs & lists
Write-Host "Amount of webs checked:"$webcount
Write-Host "Amount of lists checked:"$listcount
$webcount = "0"
}
else
{
Write-Host "No webs retrieved, please check your permissions" -ForegroundColor Red -BackgroundColor Black
$webcount = "0"
}

As you can see the script has only 1 parameter, $writeToFile. Without specifying this parameter, the script will ask for an output location, to save the results. If you do not want the script to save the output, you can call the function like this:
.\Get-SPWorkflow -writeToFile $false

I have tested this script on several environments, the largest having 4815 lists checked.

For privacy reasons, I can only show the output from my own testing environment, this is a possible outcome:

image