Click here to Skip to main content
15,885,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create the share point 2013 date column in document library using power shell?

kindly help me

Regards,

What I have tried:

i tried the below two scripts , below script is working for list only , when i execute the below script i am getting the null reference exception.
C#
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL="http://portal.crescent.com/sites/Sales"
$ListName="Vendors"
$FieldName="Date of Contract"
$RequiredField=$false
 
#Get Objects
$Web = Get-SPWeb $WebURL
$List= $Web.Lists[$ListName]
 
$List.Fields.Add($FieldName,"DateTime", $RequiredField)

or
C#
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL="http://portal.crescent.com/sites/Sales"
$sList = $WebURL.GetList($listURL)
    $spFieldType = [Microsoft.SharePoint.SPFieldType]::Datetime

    $sList.Fields.Add("OpCo",$spFieldType,$true)

    $field = $sList.Fields["OpCo"]

    $field.DefaultValue = $slist.Title

    $field.Update()

    $sList.Update()
Posted
Updated 10-Mar-17 17:04pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900