Create Form Library in SharePoint using PowerShell

Requirement: Create form library in SharePoint using PowerShell.

PowerShell to Create Form Library in SharePoint

Here is the SharePoint PowerShell script to create form library:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

Function Create-FormLibrary 
{
 Param
 ( 
  [Microsoft.SharePoint.SPWeb]$Web,
  [String] $ListName,
  [String] $Description
 )
	#Get the Form Library template
	$ListTemplate = [Microsoft.Sharepoint.SPListTemplateType]::XMLForm
 
	#Check if the list already exists
	if( ($web.Lists.TryGetList($ListName)) -eq $null)
	{
		#Create the list
		$Web.Lists.Add($ListName,$Description,$ListTemplate)
	  
		#You can Set Properties of Library such as OnQuickLaunch, etc
		$FormLib = $Web.Lists[$ListName] 
		$FormLib.OnQuickLaunch = $true
		$FormLib.Update()

		Write-Host "Form library created successfully!"
	}
	else
	{
		Write-Host "Form library already exists!"
	}
	#Dispose web object
    $Web.Dispose()    
}

#Get the Web
$web = Get-SPWeb "https://sharepoint.crescent.com/contact-us/"

#Cal the function to create library
Create-FormLibrary $web "ContactUsForms" "Form Library to store Contact us Forms"

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *