Find All InfoPath Form Libraries in SharePoint using PowerShell

During a Corporate Re-branding project, implemented a new logo, color themes all over the SharePoint sites, and now, the new Logo must be changed in All the InfoPath Form Libraries!

It was really challenging to manually find InfoPath form libraries in a Large environment with 1500+ site collections. Automation? PowerShell! Here goes the PowerShell script to find all InfoPath Form Libraries of All Site collections.

PowerShell to Find All InfoPath Form Libraries in SharePoint:

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

#For SharePoint 2007
function global:Get-SPSite($url){
    return new-Object Microsoft.SharePoint.SPSite($url)
}

#Get the web application
Write-Host "Enter the Web Application URL:"
$WebAppURL= Read-Host
$SiteColletion = Get-SPSite($WebAppURL)
$WebApp = $SiteColletion.WebApplication

#Write the CSV header
"Site Collection `t Site `t List Name `t List Url `t Docs Count `t Last Modified `t WF Count `t Live WF `t Live WF Names `t Form Template" > c:\InfoPathLibs.csv

#Loop through all site collections of the web app
    foreach ($site in $WebApp.Sites)
    {
       #Get the collection of webs
       foreach($web in $site.AllWebs)
       {
            write-host "Scaning Site" $web.title "@" $web.URL
            foreach($list in $web.lists)
            {
                If($list.BaseType -eq "DocumentLibrary" -and $list.BaseTemplate -eq "XMLForm")
                {
                   $listModDate = $list.LastItemModifiedDate.ToShortDateString()
                   $listTemplate = $list.ServerRelativeDocumentTemplateUrl
                   $listWorkflowCount = $list.WorkflowAssociations.Count
                   $listLiveWorkflowCount = 0
                   $listLiveWorkflows = [string]::Empty;
       
                   Foreach ($wf in $list.WorkflowAssociations)
                   {
                       if($wf.Enabled)
                       {
                           $listLiveWorkflowCount++
                           if ($listLiveWorkflows.Length -gt 0)
                           {
                               $listLiveWorkflows = "$listLiveWorkflows, $($wf.Name)"
                           }
                           else 
                           {
                               $listLiveWorkflows = $wf.Name
                           }
                        }
                    }
                    #Write data to CSV File
                    $site.RootWeb.Title +"`t" + $web.Title +"`t" + $list.title +"`t" + $Web.Url + "/" + $List.RootFolder.Url  +"`t" + $list.ItemCount +"`t" + $listModDate +"`t" + $listWorkflowCount +"`t" + $listLiveWorkflowCount +"`t" + $listLiveWorkflows +"`t" + $listTemplate >> c:\InfoPathLibs.csv
                }
            }
        }
    }

#Dispose of the site object
$siteColletion.Dispose()
Write-host  "Report Generated at c:\InfoPathLibs.csv" -foregroundcolor green 

Report Screenshot:
Here  is the output of the report which has all the InfoPath Form libraries of the provided web application.

Find All InfoPath Form Libraries in SharePoint Web Application

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

4 thoughts on “Find All InfoPath Form Libraries in SharePoint using PowerShell

  • Does this work for O365 as well?

    Reply
  • looks like in MOSS 2007 you need to add one more function Get-SPWebApplication.
    $MyWebURL=Get-SPWebApplication($WebAppURL)

    Then $SiteColletion = Get-SPSite($MyWebURL)
    #Get All Web Applications
    Function global:Get-SPWebApplication($WebAppURL)
    {
    if($WebAppURL -eq $null) #Get All Web Applications
    {
    #Sharepoint 2007 powershell spfarm
    $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
    $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
    $WebApps = @()
    foreach ($websvc in $websvcs) {
    foreach ($WebApp in $websvc.WebApplications) {
    $WebApps+ = $WebApp
    }
    }
    return $WebApps
    }
    else #Get Web Application for given URL
    {
    return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
    }
    }

    Reply
  • perfect thanks!!…
    is there we can also check whether form contains UserProfileConnection

    Reply
  • Nice script! Thanks for sharing.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *