Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Still very new to Powershell. I've adapted a script I found here to display information I want to see about workflows for a particular list. That looks like this:

$siteURL="https://mydomain/sites/ericrules/"
$listName="Calendar"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$list=$web.Lists[$listName]
$wfManager=$site.WorkflowManager
$associationColl=$list.WorkflowAssociations
foreach($association in $associationColl)
{
write-host $association.ParentSite, "List:" $association.ParentList, "Name:" $association.Name, "Description:" $association.Description, "Manual:" $association.AllowManual,"On Create:" $association.AutoStartCreate, "On Change:" $association.AutoStartChange,"Created:" $association.Created, "Modified:" $association.Modified
}
$web.Dispose()
$site.Dispose()

How would I adapt and generalize this to start at a singular web application and iterate through all the site collections, sites and subsites, looking at every list and outputting that data? If it was a nicely formatted text file with the quoted values as headers, that'd be ideal. A CSV would work too.

I'm still having difficulty figuring out all the for each looping going on.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

This is for all lists in a farm

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Microsoft.SharePoint.Administration.SPFarm]::Local.Services |? { 
    $_.TypeName -eq "Windows SharePoint Services Web Application" 
} |% {
    $_.WebApplications |% {
        $webapplication = $_
        Write-Host "web app"
        $webapplication.Sites |% {
            $site = $_
            Write-Host $site.Url
            $site.AllWebs |% {
                $web = $_
                Write-Host $web.Url
                $web.Lists |% {
                    $list = $_
                    Write-Host $list.Title
                    #do some stuff
                }
            }
        }
    }
}

If you just need a particular webapplication use this:

$site = new-object Microsoft.SharePoint.SPSite "https://mydomain/sites/ericrules/")
$webapplication = $site.WebApplication

Filter/Dispose as needed

Then pipe the result into Export-CSV

share|improve this answer
    
I'll see if I can get that to do what I want. –  PirateEric Apr 15 '11 at 12:29
add comment

This very long sample configures versioning setting for every site (site collection), site (subsite) and list. You will just have to adapt it with your code.

Please do not use this script in your production environment without further testing :)

Edit: Just noticed you are looking for SharePoint 2007 script, this is 2010. Sorry.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

function Get-SPList
{
    param(
        [Parameter(
            Position=0, 
            Mandatory=$true, 
            ValueFromPipeline=$true
        )]
        [Microsoft.SharePoint.SPWeb]$CurrentWeb,
        [Parameter(
            Position=1, 
            Mandatory=$false
        )]
        [string]$Title = $null

    )

    Write-Host $CurrentWeb.Url

    foreach($list in $CurrentWeb.Lists)
    {
        if($list.Hidden -eq $false -and ($Title -eq $null -or $Title -eq ""))
        {
            Write-Output $list
        }
        elseif($list.Title -eq $Title)
        {
            Write-Output $list
        }
    }
}

function Set-SPList()
{
    param(
        [Parameter(
            Position=0, 
            Mandatory=$true, 
            ValueFromPipeline=$true
        )]
        [Microsoft.SharePoint.SPList]$SPList,
        [Parameter(Mandatory=$false)]
        [bool]$EnableVersioning = $null,
        [Parameter(Mandatory=$false)]
        [bool]$EnableMinorVersions = $null,
        [Parameter(Mandatory=$false)]
        [int]$MajorVersionLimit = -1,
        [Parameter(Mandatory=$false)]
        [int]$MajorWithMinorVersionsLimit = -1
    )


    if($SPList -ne $null -and $SPList.HasExternalDataSource -eq $false)
    {
        if($EnableVersioning -ne $null)
        {   
            $SPList.EnableVersioning = $EnableVersioning
        }
        if($MajorVersionLimit -gt -1)
        {   
            $SPList.MajorVersionLimit = $MajorVersionLimit
        }

        if($SPList.BaseType -eq "DocumentLibrary")
        {
            if($EnableMinorVersions -ne $null)
            {   
                $SPList.EnableMinorVersions = $EnableMinorVersions
            }

            if($MajorWithMinorVersionsLimit -gt -1)
            {
                $SPList.MajorWithMinorVersionsLimit = $MajorWithMinorVersionsLimit
            }
        }
        $SPList.Update()
    }
}



Get-SPSite | Get-SPWeb -Limit All | ForEach-Object {Get-SPList $_ | ForEach-Object {Set-SPList $_ -EnableMinorVersions $true -EnableVersioning $true -MajorVersionLimit 5 -MajorWithMinorVersionsLimit 3}}
share|improve this answer
    
Thanks for the script Toni, this is great but I think It'll take me a while to digest it and try to adapt it to 2007 and do what I want it to. –  PirateEric Apr 15 '11 at 12:24
    
additionally, his script is for powershell 2.0 - the [parameter] attributes for cmdlet binding are not supported in powershell 1.0. –  x0n Apr 18 '11 at 20:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.