Find All InfoPath Form Libraries in SharePoint Online using PowerShell

Requirement: Find All InfoPath Form libraries in SharePoint Online

How to Find All InfoPath Form Libraries in SharePoint Online Site?

To get all form libraries in the SharePoint Online site collection, use the below PowerShell script. This script checks if the template ID of any list is 115 to decide it’s an XML Forms Library (SharePoint Online List Template IDs Reference). 

#Function to Get Form Libraries
Function Get-PnPFormLibraries
{
[cmdletbinding()]
 
    param(
    [parameter(Mandatory = $true, ValueFromPipeline = $True)]$Web,
    [parameter(Mandatory = $true, ValueFromPipeline = $False)][String] $CSVPath
    )
   
    Try {
        Write-host "Searching Web '$($Web.URL)'" -f Yellow
         
        #Get All Form libraries
        $Lists= Get-PnPProperty -ClientObject $Web -Property Lists 
        $FormLibraries = $Lists | Where-Object {$_.BaseTemplate -eq 115 -and $_.Hidden -eq $false}
 
        #Export Form Libraries Inventory to CSV
        If($FormLibraries.count -gt 0)
        {
            Write-host "`tFound '$($FormLibraries.count)' Form Librarie(s)!" -f Green
            $FormLibraries | Select Title, DefaultViewUrl, Created | Export-Csv -Path $CSVPath -NoTypeInformation -Append
        }
    }
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}
 
#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$CSVPath = "C:\Temp\FormLibs.csv"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get All Webs in the site collection and Iterate through
$Webs = Get-PnPSubWeb -Recurse -IncludeRootWeb
 
#Delete the Output Report if exists
If (Test-Path $CSVPath) { Remove-Item $CSVPath }

ForEach($Web in $Webs)
{ 
    #Call the function
    Get-PnPFormLibraries -Web $Web -CSVPath $CSVPath
}

This PowerShell script scans and extracts InfoPath Form libraries present in a given site collection and all its subsites. To scan for Infopath libraries in all sites of the tenant, use:

#Parameters
$Domain =  "CrescentIntranet" #Your Domain Name in SharePoint Online. E.g. https://Crescent.sharepoint.com
$CSVPath = "C:\Temp\InfoPathRpt.csv"
$Cred = Get-Credential

#Frame Tenant URL and Tenant Admin URL
$TenantURL = "https://$Domain.SharePoint.com"
$TenantAdminURL = "https://$Domain-Admin.SharePoint.com"

#Function to Get Form Libraries
Function Get-PnPFormLibraries
{
[cmdletbinding()]

    param(
    [parameter(Mandatory = $true, ValueFromPipeline = $False)]$Web,
    [parameter(Mandatory = $False, ValueFromPipeline = $False)][String] $CSVPath
    )
  
    Try {
        Write-host "`tSearching Web '$($Web.URL)'" -f Yellow
        
        #Get All Form libraries
        $Lists= Get-PnPProperty -ClientObject $Web -Property Lists 
        $FormLibraries = $Lists | Where-Object {$_.BaseTemplate -eq 115 -and $_.Hidden -eq $false}

        #Export Form Libraries Inventory to CSV
        If($FormLibraries.count -gt 0)
        {
            Write-host "`tFound '$($FormLibraries.count)' Form Librarie(s)!" -f Green
            $FormLibraries | Select Title, DefaultViewUrl, Created | Export-Csv -Path $CSVPath -NoTypeInformation -Append
        }
    }
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}

#Connect to Admin Center
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Cred
    
#Get All Site collections - Exclude BOT, Video Portals and MySites
$Sites = Get-PnPTenantSite -Filter "Url -like $TenantURL -and Url -notlike '-my.sharepoint.com/' -and Url -notlike '/portals/'"
   
#Iterate through all site collections
$Sites | ForEach-Object {
    #Connect to each site collection
    Connect-PnPOnline -Url $_.URL -Credentials $Cred
    
    Write-host "`nProcessing Site Collection:"$_.URL -ForegroundColor Magenta
    #Get All Webs in the site collection and Iterate through
    Get-PnPSubWeb -Recurse -IncludeRootWeb | ForEach-Object {Get-PnPFormLibraries -Web $_ -CSVPath $CSVPath}
}

Here is another article to get all info Path forms in SharePoint On-premises: PowerShell to Find All InfoPath Form Libraries in SharePoint

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!

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

Leave a Reply

Your email address will not be published.