Upload InfoPath form template to Central Administration

28/11/2013 14:54

param($formTemplateFullName)

$script:MyInvocation.MyCommand.Name

 

$AdminServiceName = "SPAdminV4"

$WasAdminServiceRunning = $true

 

# Start SharePoint Administration Service if it's not already started.

if ($(Get-Service $AdminServiceName).Status -eq "Stopped")

{

    Write-Host "Starting SharePoint Administration Service since it is not already started..." -ForegroundColor Yellow

    Write-Host

 

    $WasAdminServiceRunning = $false;

    Start-Service $AdminServiceName

 

    Write-Host "SharePoint Administration Service Started." -ForegroundColor Green

}

$infopathFormName = Split-path $formTemplateFullName -Leaf

if($infopathFormName)

{

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

    if($infopathFormTemplate)

    {

        "Uninstalling InfoPath form template {0}..." -f $infopathFormName

        $void = Uninstall-SPInfopathFormTemplate -Identity $infopathFormName -Confirm:$false

 

        while($infopathFormTemplate)

        {

            Start-Sleep 2

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

        }

 

        if(-not $infopathFormTemplate)

        {

            "Infopath form template '{0}' is uninstalled successfully." -f $infopathFormName

        }

        else

        {

            "Could not uninstall infopath form template '{0}'." -f $infopathFormName

        }

 

  }

    "Installing InfoPath form template '{0}'..." -f $infopathFormName

 

    $void = Install-SPInfopathFormTemplate -Path $formTemplateFullName -Confirm:$false

    $infopathFormTemplate = $null;

    while(-not $infopathFormTemplate)

    {

        $infopathFormTemplate = Get-SPInfoPathFormTemplate -Identity $infopathFormName

        Start-Sleep 2

    }

    if($infopathFormTemplate)

    {

        "Infopath form '{0}' is installed successfully." -f $infopathFormName

    }

    else

    {

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

    }

}

else

{

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

}