Wednesday, February 5, 2014

Get list of all InfoPath forms (with URL/Path) within a Web application-SharePoint using PowerShell

Below script helps to get list of infopath forms within a web application with their path/URL. Script also collects the names of dead/inaccessible sites (which the scripts encounters during the looping of all site collections within the web application) and outputs into a text file.

========================================================================
#change the URL to match web application where you would like to search InfoPath forms
$SPWebApp = Get-SPWebApplication ('http://yourwebapplication.com/') 

"Site Name`tList Name`tUrl`tDocs`tLast Mod`tWF`tLive WF`tLive WF Names`tTemplate" > d:\temp\AllIPDocLibs.csv

#Loop through each site in the site collection
 $cnt = $SPWebApp.Sites.count.toString()
  "Total Site collection -: $cnt "
foreach ($SPSite in $SPWebApp.Sites) #loop through all site collection
{
   $cnt = $SPSite.allwebs.count.toString()
  "Total number of Sites in collection -: $cnt "
   $SiteTitle = $SPSite.url.toString()
   "Processing Site collection $SiteTitle"
   
$url = $SiteTitle
$req = [system.Net.WebRequest]::Create($url)
$req.UseDefaultCredentials = $true
try {
       $res = $req.GetResponse()
     } catch [System.Net.WebException] {
       $res = $_.Exception.Response
     }

if ( $res.StatusCode -eq "OK" )
{
  $ErrorActionPreference="SilentlyContinue"
   foreach($webs in $SPSite.allwebs)
   {
        
#use this for output
$webTitle = $webs.title.toString()
"PROCESSING site $webTitle"

#loop though each list in the current website
for($i=0;$i -ne $webs.lists.count;$i++)
{
$list = $webs.lists[$i]
#variables for output.
$listTitle = $list.toString()
$listUrl = $list.DefaultViewUrl
$listCount = $list.ItemCount

if( $list.BaseType -eq "DocumentLibrary"  -and
$list.BaseTemplate -eq "XMLForm")
{
$listModDate = $list.LastItemModifiedDate.ToShortDateString()
$listTemplate = $list.ServerRelativeDocumentTemplateUrl
$listWorkflowCount = $list.WorkflowAssociations.Count
$listLiveWorkflowCount = 0
$listLiveWorkflows = ""
foreach ($wf in $list.WorkflowAssociations)
{
if ($wf.Enabled)
{
$listLiveWorkflowCount++
if ($listLiveWorkflows.Length -gt 0)
{
$listLiveWorkflows = "$listLiveWorkflows, $($wf.Name)"
}
else 
{
$listLiveWorkflows = $wf.Name
}
}
}
"$webTitle`t$listTitle`t$listUrl`t$listCount`t$listModDate`t$listWorkflowCount`t$listLiveWorkflowCount`t$listLiveWorkflows`t$listTemplate" >> d:\temp\AllIPDocLibs.csv
}
}
$webs.Dispose()
    }
}
else
   {  Add-Content d:\temp\DeadSites.txt "`n $SiteTitle" }
    $SPSite.Dispose()
}
    [GC]::Collect()
#Dispose of the site object
$SPWebApp.Dispose()
"Done"
========================================================================

No comments:

Post a Comment