0

Is there a way to get the list of InfoPath forms hosted in form libraries, list inside an entire site collection in SharePoint Online

The output should give,

Site Name:

Site URL:

SharePoint List/Library Name:

Thanks!

2
  • Are you looking for forms stored in libraries, or custom list forms? Commented Apr 17, 2018 at 16:12
  • Hi Mike,Not all the forms in libraries, but those Libraries and List that have InfoPath enabled. The list should have infopath form by default. I want those type of list and libraries from a site collection.
    – Selva
    Commented Apr 17, 2018 at 19:22

2 Answers 2

3

You can do this with the PNP cmdlets. (https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps)

Install-Module SharePointPnPPowerShellOnline

The following works, but I don't think it is ideal (reconnects for each web). Delete the Write-Host line to remove the "checking" messages.

$rootUrl = "https://yourDomain.sharepoint.com"  # enter your URL

$cred = Get-Credential   # enter credential with needed permissions

Connect-PnPonline $rootUrl -credential $cred;

Get-PnPTenantSite | 
  foreach { 
    Connect-PnPonline $_.url -credential $cred; 
    #####Get-PnPWeb -Includes webs | 
    #####  select -ExpandProperty webs | 
    Get-PnPSubWebs -Recurse |
      where { $_.url -like $rootUrl+"*" } |   # skip app sites and OneDrives
      foreach { 
        Write-Host "Checking " $_.Url; # status message, delete if not needed.
        $parentTitle = $_.Title; 
        $parentUrl = $_.Url; 
        Get-PnPList -Web $_ -Includes Forms | 
        foreach { $listTitle = $_.Title; $_ } | 
        select -ExpandProperty Forms | 
        where { $_.ServerRelativeUrl -like '*displayifs.aspx' } | 
        select @{l="Web Title";e={$parentTitle}}, 
               @{l="Web URL";e={$parentUrl}}, 
               @{l="List Title";e={$listTitle}}
     }
  }
2
  • Thanks Mike, Your code worked the way i wanted, except for one thing. The power-shell script does not loop through all the sub-sites beyond level 1. There are some list/libraries beyond Level 1. Please advise.
    – Selva
    Commented Apr 20, 2018 at 16:34
  • I updated the script to use "Get-PnPSubWebs -Recurse". Give it another try. Commented Apr 20, 2018 at 21:05
1

Borrowed some of the Script from Mike but I changed it to look at Doc Libraries as well as lists. This script connects to each parent and child / site collection and checks for lists and libraries and excludes system lists. For Lists it checks the form URL and for Doc Libraries it checks if the Form Content Type is in use (which is usually the case if an InfoPath library is) on that site. I'm sure there are other ways but I thought I'd share how I was able to get a script to generate all sites using InfoPath forms.

$rootUrl = "https://yourDomain.sharepoint.com"   # enter your URL
Connect-PnPonline $rootUrl 

Get-PnPTenantSite | 
foreach { 
Write-Host "Checking " $_.Url; # status message, delete if not needed.
Connect-PnPonline $_.url

    $web = Get-PnPWeb

    $parentTitle = $web.Title
    $parentUrl = $web.Url

    $listsIncForm = Get-PnPList 



    forEach ( $list in $listsIncForm) {
        $listTitle = $list.Title
        $listType = $list.BaseTemplate
        $listUrl = $list.DefaultViewUrl



        if ( $listType -eq 100 -or $listType -eq 101 ) {
            $currList = Get-PnPList $listTitle -Includes ContentTypes, Forms, IsSystemList

            $listForms = $currList.Forms
            $isSysList = $currList.IsSystemList

            if ( $isSysList ) {
                #Write-Host 'Sys List Ignore'
            } else {
                if ( $listType -eq 101 ) {
                    $contentTAllow = $currList.AllowContentTypes
                    if ( $contentTAllow ) {
                        $contentTyps = $currList.ContentTypes
                        forEach ($contType in $contentTyps) {
                            if ( $contType.Name -eq 'Form' ) {
                                Write-Host "InfoPath Found in Library" $listTitle " at URL " $listUrl -ForegroundColor Green
                            }
                        }
                    }

                }
                else {
                    forEach ( $listFm in $listForms ) {
                        $listPath = $listFm.ServerRelativeUrl
                        if ( $listPath -like '*displayifs.aspx' ) {
                            Write-Host 'InfoPath Found in List ' $listTitle " at URL " $listUrl -ForegroundColor Green

                        }
                    }
                }
            }

        }
    }

Get-PnPSubWebs -Recurse |
  where { $_.url -like $rootUrl+"*" } |   # skip app sites and OneDrives
  foreach { 
    Write-Host "Checking " $_.Url; # status message, delete if not needed.

    Connect-PnPOnline -Url $_.Url

    $web = Get-PnPWeb

    $parentTitle = $web.Title
    $parentUrl = $web.Url

    $listsIncForm = Get-PnPList 



    forEach ( $list in $listsIncForm) {
        $listTitle = $list.Title
        $listType = $list.BaseTemplate
        $listUrl = $list.DefaultViewUrl



        if ( $listType -eq 100 -or $listType -eq 101 ) {
            $currList = Get-PnPList $listTitle -Includes ContentTypes, Forms, IsSystemList

            $listForms = $currList.Forms
            $isSysList = $currList.IsSystemList

            if ( $isSysList ) {
                #Write-Host 'Sys List Ignore'
            } else {
                if ( $listType -eq 101 ) {
                    $contentTAllow = $currList.AllowContentTypes
                    if ( $contentTAllow ) {
                        $contentTyps = $currList.ContentTypes
                        forEach ($contType in $contentTyps) {
                            if ( $contType.Name -eq 'Form' ) {
                                Write-Host "InfoPath Found in Library" $listTitle " at URL " $listUrl -ForegroundColor Green
                            }
                        }
                    }
                }
                else {
                    forEach ( $listFm in $listForms ) {
                        $listPath = $listFm.ServerRelativeUrl
                        if ( $listPath -like '*displayifs.aspx' ) {
                            Write-Host 'InfoPath Found in List ' $listTitle " at URL " $listUrl -ForegroundColor Green

                        }
                    }
                }
            }
        }
      }
   }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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