Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |

Friday, June 20, 2014

How To: Create Multi line of Text and single line of text fields in SharePoint using powershell

Below script will helps us on how to create single line of text and multi line of text fields in SharePoint using PowerShell. please refer my previous posts on below scenarios:

  1. Create a new list in SharePoint using powershell?
  2. Check whether the list exits or not?
  3. Create a new field in SharePoint list using powershell
  4. Add items to the list in SharePoint using powershell?

Download URL: Click here to download script

In SharePoint, we can create multi line of text fields with 3 types of attributes[see below image]


Below PowerShell scripts will works on SharePoint 2013/2010/2007
===================================================================================

$listname="ListName"

===================================================================================
$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()

===================================================================================

function Add-SPMutliLineoftextField([string]$listName, 
        [string]$DisplayName, 
        [string]$Name, 
        [string]$Required, 
        [string]$NumLines, 
        [string]$RichText, 
        [string]$RichTextMode)
{
   $OpenList = $docWeb.Lists[$listName]
   $multiLineCol1 = ""
   $OpenList.Fields.AddFieldAsXml($multiLineCol1,$true,
   [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)   
}

function Add-SPSingleLineOfTextField([string]$listName, 
         [string]$DisplayName, 
         [string]$Name, 
         [string]$Required, 
         [string]$DateType)
{
  $OpenList = $docWeb.Lists[$listName]
  $firstNameColXml = "" 
  $OpenList.Fields.AddFieldAsXml($firstNameColXml,$true, 
  [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView) 
}

====================================================================================

Write-Host "`n Adding fields to the $listname list `n" 

//To create a single line of text field
Add-SPSingleLineOfTextField -listName $listname -Name singlelineoftextfieldName -DisplayName singlelineoftextfieldName -Required FALSE

//To create a multiline of rich text field
Add-SPMutliLineoftextField  -listName $listname -Name mutliLineoftextFieldName  -DisplayName mutliLineoftextFieldName  -Required TRUE  -NumLines 8 -RichTextMode Compatible -RichText TRUE

//To create a multiline of enhanced rich text field
Add-SPMutliLineoftextField  -listName $listname -Name mutliLineoftextFieldName  -DisplayName mutliLineoftextFieldName  -Required TRUE  -NumLines 8 -RichTextMode FullHtml -RichText TRUE

//To create a multiline of plain text field
Add-SPMutliLineoftextField  -listName $listname -Name mutliLineoftextFieldName  -DisplayName mutliLineoftextFieldName  -Required TRUE  -NumLines 8 -RichTextMode FullHtml -RichText FALSE

====================================================================================
Please let me know if faced any issues while using the above scripts and provide your valuable feedback.

Thanks,
Sasi Kumar Reddy

No comments:

Post a Comment