Activate Infopath forms on all site collections

07.03.2014 14:41

#Script to take all your infopath forms in folder, upload to central administration and activate it on selected site collections (or all)


#ActivateInfoPathForm.ps1 is on link

https://mypowershell.webnode.sk/news/activate-infopath-form-on-site-collection/

#UploadInfoPathForm.ps1 is on link

https://mypowershell.webnode.sk/news/upload-infopath-form-template-to-central-administration/


Add-PSSnapin microsoft.sharepoint.powershell
$ErrorActionPreference = "Stop"
$location = Split-Path $script:MyInvocation.MyCommand.Path

#  ============================  input parameters ================================

#$sourceFolderPath = "c:\Users\Administrator\Documents\Mosr-scripts\ActivateForms\FormulareZaskis\Vyber\"
$sourceFolderPath = Join-path $location "\Forms\"

#path to scripts 'UploadInfoPathForm.ps1' and 'ActivateInfoPathForm.ps1'
$scriptLocation = (get-item $sourceFolderPath).parent.parent.parent.FullName

#site collection list where to activate forms
$siteCollectionUrls = get-spsite -limit all ' select -ExpandProperty Url
#$siteCollectionUrls = @("https://server/sitecollection1", "https://server/sitecollection2")

#  ============================  end of required parameters ================================


 function Heading($heading)
 {
  Write-Host "==============================================================" -ForegroundColor Green
 Write-Host "                     " $heading "                             " -ForegroundColor Green
 Write-Host "==============================================================" -ForegroundColor Green
 }

#Get all xsn files from folder
$formsFullPaths = Get-ChildItem -LiteralPath $sourceFolderPath ' where {$_.Extension -eq ".xsn"} ' select -ExpandProperty FullName

if($formsFullPaths -ne $null)
{
    #Upload InfoPath forms to Central Administration
    $count = $formsFullPaths.Count
    $i=1
    foreach($eForm in $formsFullPaths)
    {
        Heading ("{0}/{1}" -f $i, $count)
        & $scriptLocation\UploadInfoPathForm.ps1 -formTemplateFullName $eForm
        $i++
    }

    #Activate each form on each site collection
    $i=1
    foreach($eForm in $formsFullPaths)
    {
        Heading ("{0}/{1}" -f $i, $count)
        foreach($siteCollectionUrl in $siteCollectionUrls)
        {
            & $scriptLocation\ActivateInfoPathForm.ps1 -siteUrl $siteCollectionUrl -formTemplateFullName $eForm
        }
        $i++
    }
}
else
{
    "No forms found in '{0}'" -f $sourceFolderPath
}