Activate InfoPath form on site collection

28/11/2013 15:44

#this script only activates form template already installed in Central Administration. Installing is described in another blog post (follow InfoPath tag)

 

$formTemplateFullName = "c:\temp\yourform.xsn"

$siteUrl = https://server/yoursitecolectionurl

 

param($siteUrl, $formTemplateFullName)

 

if($siteUrl)

{

    $site = Get-SPSite -Identity $siteUrl

    if($site)

    {

        $infopathFormName = Split-path $formTemplateFullName -Leaf

        if($infopathFormName)

            {

                $infopathFormTemplate = Get-SPInfoPathFormTemplate -Identity $infopathFormName -ErrorAction SilentlyContinue

                if($infopathFormTemplate)

                {

                    "Activating Infopath form '{0}' on site collection '{1}'..." -f $infopathFormName, $siteUrl

                    $void = Enable-SPFeature -Identity $infopathFormTemplate.FeatureId -Url $siteUrl -Confirm:$false -ErrorAction SilentlyContinue

                    $infopathFormFeature = $null;

                    while(-not $infopathFormFeature)

                    {

                        Start-Sleep 2

                        $infopathFormFeature = Get-SPFeature -Site $site | Where-object {$_.Id -eq $infopathFormTemplate.FeatureId}

                    }

                    if($infopathFormFeature)

                    {

                        "Infopath form '{0}' is successfully activated on site collection '{1}'." -f $infopathFormName, $siteUrl

                    }

                    else

                    {

                        "Could not activate form template '{0}' at site collection '{1}'." -f $infopathFormName, $siteUrl

                    }

                }

                else

                {

                    "Could not install infopath form template '{0}' to '{1}'." -f $infopathFormName, $siteUrl

                }

            }

            else

            {

                "Invalid infopath form template name '{0}' or template not installed." -f $infopathFormName

            }

        }

        else

        {

            "Could not find site collection at '{0}'" -f $siteUrl

            }

}