Deploy Custom List Forms Using PowerShell In SharePoint 2013

In this article I am going to explain how we can deploy Custom List Forms using PowerShell, this is mainly useful to deploy custom pages in multiple environments instead of recreating list.

Steps to Deploy Custom Forms:

  1. Create test list in your site.

    Create test list in your site

  2. Create custom List form using SharePoint Designer and make that as default one for creating new item.

    Create custom List from using SharePoint Designer

    add new custom from

  3. We can see the new custom form to create new item to the list.

    new custom from

  4. After deploying this list to different/same site, there is a change in requirement to add new column.

    This change can be deployed by creating new list in the target server but it is going to affect the data which is already created.

    The second option is to deploy only the list form using PowerShell.

  5. Export the updated custom form to local drive and deploy using PowerShell script.


  6. Open Windows PowerShell management studio or PowerShell ISE and execute the following PowerShell script to deploy files.

    run as administrator

  7. PowerShell Script code:
    1. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")  
    2. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Publishing")  
    3. [System.Reflection.Assembly]::LoadWithPartialName("System")  
    4. [System.Reflection.Assembly]::LoadWithPartialName("System.IO")  
    6. $siteUrl = "http://RKSite/"  
    7. $listName = "RK_List"  
    8. $templateFilesFolderPath = "C:\RK\Custom list forms\Forms"  
    10. $web = Get-SPWeb -Identity $siteUrl  
    11. if($web)  
    12. {  
    13.     try  
    14.     {  
    15.         $list = $web.Lists.TryGetList($listName)  
    16.         $files = Get-ChildItem -Path $templateFilesFolderPath -Force -Recurse  
    17.         foreach ($file in $files)  
    18.         {  
    19.             $stream = $file.OpenRead()  
    20.             $completedFileName = $list.RootFolder.Files.Add($file.Name, $stream, [Microsoft.SharePoint.SPTemplateFileType]::FormPage)  
    21.             $stream.Close()  
    22.             Write-Host $completedFileName.Name  "Uploaded into the list"  
    23.         }  
    24.         $list.Update();  
    25.     }  
    26.     catch  
    27.     {  
    28.         Write-Host $($_.Exception.Message)  
    29.     }  
    30. }  
    31. else  
    32. {  
    33.     Write-Host "Site not exist"  
    34. }  
    35. Write-Host "--- Script Completed ---"  
  8. PowerShell Configuration:

    Site Url = <<Site url to deploy the form>>
    List Name = <<List name to deploy the from>>
    templateFilesFolderPath = <<Local folder path for list forms>>

  9. Execute the script using the following command:



  10. You can see the updated custom list form in target list.

    updated custom list from in target list

    add new column

Important Note: If we are going to update this form in different server we need to update the target list id in the custom form.

We need to replace all list ids in the custom form otherwise it will throw an error, better select replace all option

select replace all option

Up Next
    Ebook Download
    View all
    View all