Add Column to List and Content type Using Powershell

Below is the code you need to execute to add a column to List and Content type using PowerShell. Copy below code to notepad, rename the notepad with CreateField.ps1 and then execute the code from PowerShell.

PowerShell

#####################Code Starts

# Add PsSnapin if not already added

if ( (Get-PSSnapin -Name Microsoft.Sharepoint.Powershell -ErrorAction SilentlyContinue) -eq $null )

{

Add-PsSnapin Microsoft.Sharepoint.Powershell

}

# Call the function with WebURL, List Name – where you want to add column

# FieldName – the nae of the filed you want to add – type is hardcoded in below function

# Contenttype name – the content type name you want to add field to

function CreateColumn($webUrl, $listName, $fieldName, $contentTypeName )

{ $web = Get-SPWeb $webUrl

Write-Host “$($web.URL)”

$pageList = $web.Lists[$listName]

Write-Host “$($pageList.URL)”

$pageFieldisNewTillDate = $pageList.Fields.Add($fieldName, “DateTime”, 0)

$pageList.Fields[$pageFieldisNewTillDate].Title = $fieldName

$pageList.Fields[$pageFieldisNewTillDate].Description = “Description here”

$pageList.Fields[$pageFieldisNewTillDate].DisplayFormat = “DateOnly”

$pageList.Fields[$pageFieldisNewTillDate].Update()

$pageList.Update();

$field = $pageList.Fields[$fieldName]

Write-Host “Field created” + “$($field)”

$fieldlink = New-Object Microsoft.SharePoint.SPFieldLink $field

#Write-Host “$($fieldlink)”

$contentTypeContact = $pageList.ContentTypes[$contentTypeName]

Write-Host “$($contentTypeContact.Title)”

#add the new field to content type you need

$contentTypeContact.FieldLinks.Add($fieldlink)

$contentTypeContact.Update()

$web.Dispose();

}

# Function is called with valied input parameters

CreateColumn -webUrl “https://xxx.com/Contacts” -listName “Pages” -fieldName “isValidTillDate” -contentTypeName “Contacts”

CreateColumn -webUrl “https://xxx.com/KnowledgeUpdate” -listName “Pages” -fieldName “isValidTillDate” -contentTypeName “KnowledgeUpdate”

#####################Code Ends

Feel free to drop me email on bipinparshottam@gmail.com, skype:bipin.pankhania incase of queries.

Percentage Complete Progress Bar in SharePoint 2013

% Complete Progress bar in SharePoint 2013

Need to add following Javascript code to MasterPage Gallary. Here we have added tasklist.js file, need to select below content type and other properties.AddMaster

Copy paste below code between start and end to text file, rename it with TaskList.Js

Code:

/*****************Starts************************/

codeFunction

//Please drop me an email if you want code, as I am unable to copy paste in my blog, hence I have given the screenshot of the code.

/******************Ends*******************/

Need to Add TaskList -> List View webpart to specific page, Edit webpart, under Miscellaneous properties of webpart, provide the path of the TaskList.Js file from where it needs to pick up latest JavaScript code.

WebpartProperties

After this click on OK , Save and Check in the page. This will show task list %complete as follows.

ProgressBar

The main code in TaskList.Js is below, this code arranges nested div and span in proper style, with modification in Span, one can choose to display % Left or right aligned.

Below is the main code from JavaScript function

code

————————————–

for queries, suggestions, feedback contact me on

email :bipinparshottam@gmail.com

skype: bipin.pankhania

Create Host named site collection

Create Host named site collection using PowerShell
Need to execute below Script to Create Host named site collection using PowerShell.

Add-PSSnapin Microsoft.Sharepoint.Powershell

New-SPSitehttp://siteurl’ -HostHeaderWebApplication ‘http://webapplicationurl’ -Name ‘TitleYouwanttoCreate’ -Description ‘Site description’ -OwnerAlias ‘admin’ -language 1033 -Template ‘BLANKINTERNET#0’

Above fields are self-explanatory, need to supply
SPSite -> SiteCollection URL -> the way you want to create it for SPSite
HostHeaderWebApplication -> Webapplication URL on top of which you need to create Site Collection.
Name – Site Collection name
Description – Site Collection description
OwnerAlias – System Admin account
Language -1033 for UK English
Template – the template code you need to create Site Collection.

————————————–

for queries, suggestions, feedback contact me on

email :bipinparshottam@gmail.com

skype: bipin.pankhania

via SharePoint

With my site I wish to give overview of my SharePoint tasks so far this comprises Issues, Learning and few sample codes, while I tried to write technical blog on SharePoint would like to give a glimpse of  my personal life to improve trust with my readers and my writing skills.

Wish to have a beautiful writing, corralled my way!