Find all InfoPath forms in SharePoint using PowerShell

[Verified]: Find all InfoPath forms in SharePoint using PowerShell

One comment

Loading

In this find all InfoPath forms in SharePoint article, we learn about how to find all InfoPath forms in SharePoint using the PowerShell script which includes a list and template form.

Business Scenario: Find all InfoPath forms in SharePoint

Over the years, people from the various sector has been using the Infopath form as it is a great tool, easy to develop any type of form in very less time, and it is part of the Microsoft Office product – I personally still like this product or tool very much. However, Microsoft does not recommend continuing with the InfoPath form as they are going to stop support after 2023 – at present this product is deprecated.

Considering this scenario, we need to plan for the migration of these InfoPath forms that you have in your ton-premise server. To be more concise, let’s say you have lots of InfoPath forms in the SharePoint on-premise environment, now you are planning to migrate your on-premise sites to SharePoint Online, then definitely we need to re-develop the Infopath form using modern technologies like Power Apps, Nintex Forms, Nintex Cloud form tool.

So, before starting the migration we must have a detail of all InfoPath forms inventory like these forms hosted in which list/library so that we could analyze the InfoPath forms beforehand before we start developing these forms using other modern technologies or tools.

Find all InfoPath forms in SharePoint and export them into a CSV file using PowerShell script

Using the below PowerShell script we can find all InfoPath forms and export them into a CSV file.


#The below script is used to get the all infopath form details from the SharePoint 2016 on-premise environment using the PowerShell script.
cls

$PSshell = Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorVariable err -ErrorAction SilentlyContinue
if($PSshell -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$fileName = "InfopathFormInventoryReport"
#'yyyyMMddhhmm yyyyMMdd
$enddate = (Get-Date).tostring("yyyyMMddhhmmss")
#$filename = $enddate + '_VMReport.doc'
$logFileName = $fileName +"_"+ $enddate+"_Log.txt"
$invocation = (Get-Variable MyInvocation).Value
$directoryPath = Split-Path $invocation.MyCommand.Path

$directoryPathForLog=$directoryPath+"\"+"LogFiles"
if(!(Test-Path -path $directoryPathForLog))
{
New-Item -ItemType directory -Path $directoryPathForLog
#Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
#$logPath = $directoryPath + "\" + $logFileName

$logPath = $directoryPathForLog + "\" + $logFileName

$isLogFileCreated = $False

function Write-Log([string]$logMsg)
{
if(!$isLogFileCreated){
Write-Host "Creating Log File..."
if(!(Test-Path -path $directoryPath))
{
Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
else
{
$script:isLogFileCreated = $True
Write-Host "Log File ($logFileName) Created..."
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}
else
{
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}

#######The below function will get the details from SharePoint on-premise web application whether they contain infopath form or not.############################

function GetInfopathFormDetailsFromSharePointOnPremise()
{
param
(
[Parameter(Mandatory=$true)] [string] $WebAppURL

)

$targetReportPath="C:\InfoPathFormsInventory.csv"
#This is an array to store ResultItem - PSObjects
$ResultCollArray = @()

#Get all webs of the given web application
$WebsCollection = Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All | Get-SPWeb -Limit All

$formCount=0;
#Looping thru the collection of webs from the web collection.
foreach($oneSPWeb in $WebsCollection)
{

#Get all lists/libraries with InfoPath List Forms in use condition.
foreach ($oneList in $oneSPWeb.Lists)
{
$ResultItem = new-object PSObject

if($oneList.ContentTypes[0].ResourceFolder.Properties["_ipfs_infopathenabled"] -eq $true)
{
$formCount=$formCount+1;
$listModDate = $oneList.LastItemModifiedDate.ToShortDateString()

Write-Host "The code has found an InfoPath form at: $($oneSPWeb.URL), $($oneList.oneList)"
#$ResultItem = new-object PSObject

try
{

$ResultItem | add-member -membertype NoteProperty -name "Site URL" -Value $oneSPWeb.Url
$ResultItem | add-member -membertype NoteProperty -name "List Name" -Value $oneList.Title
$ResultItem | add-member -membertype NoteProperty -name "List URL" -Value "$($oneSPWeb.Url)/$($oneList.RootFolder.Url)"
$ResultItem | add-member -membertype NoteProperty -name "Template" -Value $oneList.ContentTypes[0].ResourceFolder.Properties["_ipfs_solutionName"]
$ResultItem | add-member -membertype NoteProperty -name "ListLastModifiedDate" -Value $listModDate

$ResultCollArray += $ResultItem

}
catch
{
$ErrorMessage = $_.Exception.Message +"in the GetInfopathFormDetailsFromSharePointOnPremise script!: "
Write-Host $ErrorMessage -BackgroundColor Red
Write-Log $ErrorMessage

}
}
if( $oneList.BaseType -eq "DocumentLibrary" -and $oneList.BaseTemplate -eq "XMLForm")
{
$formCount=$formCount+1;
#$ResultItem = new-object PSObject
try
{

$listModDate = $oneList.LastItemModifiedDate.ToShortDateString()
Write-Host "The code has found an InfoPath form at: $($oneSPWeb.URL), $($oneList.oneList)"
$ResultItem | add-member -membertype NoteProperty -name "Site URL" -Value $oneSPWeb.Url
$ResultItem | add-member -membertype NoteProperty -name "List Name" -Value $oneList.Title
$ResultItem | add-member -membertype NoteProperty -name "List URL" -Value "$($oneSPWeb.Url)/$($oneList.RootFolder.Url)"
$ResultItem | add-member -membertype NoteProperty -name "Template" -Value $oneList.ServerRelativeDocumentTemplateUrl
$ResultItem | add-member -membertype NoteProperty -name "ListLastModifiedDate" -Value $listModDate
$ResultCollArray += $ResultItem

}
catch
{
$ErrorMessage = $_.Exception.Message +"in the GetInfopathFormDetailsFromSharePointOnPremise script!: "
Write-Host $ErrorMessage -BackgroundColor Red
Write-Log $ErrorMessage

}

}
Write-Host "Form Count: " $formCount
}

#Export the results to a CSV File in the given location.
#$ResultCollArray | Export-csv $targetReportPath -notypeinformation
#Write-Host "The InfoPath Forms Report has been generated successfully!" -f Green

}

#Export the results to a CSV File in the given location.
$ResultCollArray | Export-csv $targetReportPath -notypeinformation
Write-Host "The InfoPath Forms Report has been generated successfully!" -f Green

}

####################Testing - calling the function########################################################

try
{

GetInfopathFormDetailsFromSharePointOnPremise "http://server:port" #Your WebAppURL

$message="The GetInfopathFormDetailsFromSharePointOnPremise function execution has been completed successfully."
Write-Host $message -BackgroundColor Green

}
catch
{
$ErrorMessage = $_.Exception.Message +"in the GetInfopathFormDetailsFromSharePointOnPremise script!: "
Write-Host $ErrorMessage -BackgroundColor Red
Write-Log $ErrorMessage
}
####################Testing - calling the function ends here####################################

Note:

From the above code the below two lines are key to check the InfoPath Form condtion:

  • if($oneList.ContentTypes[0].ResourceFolder.Properties[“_ipfs_infopathenabled”] -eq $true)
  • if( $oneList.BaseType -eq “DocumentLibrary” -and $oneList.BaseTemplate -eq “XMLForm”)

First, if the condition checks whether the “_ipfs_infopathenabled” list property is set to true and the second condition checks that the list base type is “Document Library” and the base template is “XMLForm”.

Summary: Find all InfoPath forms in SharePoint

Thus, in this article, we have learned about how to find all InfoPath forms from SharePoint on-premise using the PowerShell script.

See Also: Find all InfoPath forms in SharePoint

You may also like the following SharePoint PowerShell tutorials:

Download SharePoint Online PDF Book

Download SharePoint Online & Office 365 Administration eBook

Buy the premium version of SharePoint Online & Office 365 administration eBook from here:



Buy SharePoint Online & Office 365 Administration eBook


 

Get the free demo PDF eBook from here:

FREE DOWNLOAD

Send download link to:

Subscribe to get exclusive content and recommendations every month. You can unsubscribe anytime.

 

About Post Author

1 comments on “[Verified]: Find all InfoPath forms in SharePoint using PowerShell”

Do you have a better solution or question on this topic? Please leave a comment