Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |
Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Monday, December 1, 2014

Re-Order the sharepoint site columns in content type using powershell script


$URL = "http://LocalHost/”
$site = New-Object Microsoft.SharePoint.SPSite($URL)
$web = $site.openweb()
$myCustomContentype=$web.ContentTypes["MySiteContentType"]
$newFieldOrder = @("Title","MyCOl1","MyCol3","FileLeafRef","MyCOl5","MyCol2")
$myCustomContentype.FieldLinks.Reorder($newFieldOrder)
$myCustomContentype.Update()
Name:  Only refer the Sharepoint internal names for reorder.  
Example: Internal name for “Title” is “FileLeafRef

Tuesday, November 25, 2014

Create sharepoint site in Office365 using powershell script

Just do copy/paste the below script in you powershell and see the magic..You will be able to new site in your office 365 application.

Am sharing the below script to all of my SharePoint colleges once did the experiments from my side.

*********************************************************************************
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("User-Agent","Mozilla/4.0+")      
$wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type –Path "C:\Program Files\SharePoint Client Components\16.0\Assemblies\Microsoft.Online.SharePoint.Client.Tenant.dll"
$siteUrl = “http://xxx.xxxx.com”
$password = convertto-securestring "*****" -asplaintext -force
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("username", $password)
$ctx.Credentials = $credentials
$webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$webCreationInformation.Url = "URLName"
$webCreationInformation.Title = "Title"
$webCreationInformation.WebTemplate = "STS#0"
$newWeb = $ctx.Web.Webs.Add($webCreationInformation)
$ctx.Load($newWeb)
$ctx.ExecuteQuery()
**********************************************************************************
Please let me know for any concerns.

-Thanks,
Sasi Kumar Reddy
https://sharepointquicksolutions.blogspot.com

Friday, November 14, 2014

SharePoint choice field using powershell

$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()
$lncustomListName listName
$CustomfieldName = "MyChoiceColumn"

/* To create choice field */
Add-SPMultiChoiceField -listName $lncustomListName

/* Method to create choice field */
function Add-SPMultiChoiceField([string]$listName)
{
  $OpenList = $docWeb.Lists[$listName]
  $multiChoiceCol = "<Field Name='"+ $CustomfieldName +"' Type='MultiChoice' FillInChoice='FALSE' DisplayName='"+ $CustomfieldName +"'><Default>MyChoice1</Default><CHOICES><CHOICE>MyChoice2</CHOICE><CHOICE>ERM</CHOICE><CHOICE>MyChoice3</CHOICE></CHOICES></Field>"
 $OpenList.Fields.AddFieldAsXml($multiChoiceCol,$true,
 [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView) 
}

Thursday, September 25, 2014

create sharepoint boolean field using powershell script

Please visit my below post which helps on how to create sharepoint list using powershell script:
Create sharepoint list using powershell script

Note: By default, below method sets the boolean field as Yes(1). If you want as No(0), provide the 0 value to the "DefaultValue"
****************************************************************************************
$lncustomListName listName
$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()

/* To create Boolean field */
Add-SPBooleanField -listName $lncustomListName -Name EmailFlag -DisplayName EmailFlag -Required TRUE -DefaultValue 1

/* Method to create boolean field */
function Add-SPBooleanField([string]$listName, [string]$DisplayName, [string]$Name, [string]$Required,[string]$DefaultValue)
{
  $OpenList = $docWeb.Lists[$listName]
  $fldXml = "<Field Type='Boolean' DisplayName='"+$DisplayName +"' Required='"+ $Required +"' Name='"+ $Name +"'>
           <Default>$DefaultValue</Default>
           </Field>"
  $OpenList.Fields.AddFieldAsXml($fldXml,$true,
  [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)
}

*****************************************************************************************
Please let me know if faced any issues.

Sunday, September 21, 2014

Create sharepoint datetime control using powershell script

Visit my previous post for to create a list through powershell script
Create list using powershell script
*********************************************************************************
$lncustomListName listName
$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()

/* To create DateTime field for allow only one user/group */
Add-SPDateTimeField -listName $lncustomListName -Name DateTimeFieldName  -DisplayName DateTimeFieldName  -DateType DateOnly -Required FALSE

/* Method to create people DateTime field */
function Add-SPDateTimeField([string]$listName, [string]$DisplayName, [string]$Name, [string]$Required, [string]$DateType)
{
   $OpenList = $docWeb.Lists[$listName]
   $fldXml = "<Field Type='DateTime' DisplayName='"+ $DisplayName +"' Format='"+ $DateType +"' Required='"+ $Required +"' Name='"+ $Name +"'/>"
   $OpenList.Fields.AddFieldAsXml($fldXml,$true,
   [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)
}
**********************************************************************************
Please let me know if faced any issues.

Saturday, September 13, 2014

Create sharepoint multi people picker field through powershell script

Visit my previous post for to create a list through powershell script and to create people picker for allow single user/group
Create a new sharepoint list using powershell script
Create a people picker column to allow single user/group

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

/* To create people picker field for allow mutliple users and groups */

Add-SPUserField -listName $lncustomListName -DisplayName MyList -Name MyList -Required TRUE

function Add-SPMultiUserField([string]$listName, [string]$DisplayName, [string]$Name, [string]$Required)
{
   $OpenList = $docWeb.Lists[$listName]
   $fldXml = "<Field Type='User' DisplayName='"+ $DisplayName +"' Required='"+ $Required +"' Name='"+ $Name +"'/>"
   $OpenList.Fields.AddFieldAsXml($fldXml,$true,
   [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)
   $fieldname=$OpenList.Fields[$DisplayName]
   $fieldname.AllowMultipleValues=$true
   $fieldname.update()  
}
*********************************************************************************

Create sharepoint People Picker field through powershell script

Visit my previous post for to create a list through powershell script
Create list using powershell script

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

/* To create people picker field for allow only one user/group */
Add-SPUserField -listName $lncustomListName -DisplayName MyList -Name MyList -Required TRUE

/* Method to create people picker field
function Add-SPUserField([string]$listName, [string]$DisplayName, [string]$Name, [string]$Required)
{
   $OpenList = $docWeb.Lists[$listName]
   $fldXml = "<Field Type='User' DisplayName='"+ $DisplayName +"' Required='"+ $Required +"' Name='"+ $Name +"'/>"
   $OpenList.Fields.AddFieldAsXml($fldXml,$true,
   [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)   
}
*******************************************************************************
Please let me know if faced any issues.

Thursday, June 19, 2014

How To: Create new field and add items in SharePoint list using PowerShell


Below code will help us on below scenerios:
  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?

How To: Create new list in sharepoint using powershell: 2013/2010/2007

Below code will help us to create a SharePoint list through PowerShell:
 
==================================================================================

$siteURL= "your site URL"

$ListName ="List Name"

$ListName1 ="ListName1"

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

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

$TemplateType = $docWeb.ListTemplates["Custom List"]

function Create-SPList([string]$listName, [string]$description)
{
 $exLst = $docWeb.Lists[$listName]

        //Create new list if already doesn't exists
 if($exLst -eq $null)
 {
  Write-Host "`n List does not exist. Creating $listName list`n"
  [void]$docWeb.Lists.Add($listName, $description, $TemplateType)
  $docWeb.Update()
 }  
}


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

//To create list name

Create-SPList -listName  $ListName   -description "List Description"

Create-SPList -listName1 $ListName1  -description "List Description1"

===================================================================================
Please let me know if face any issues while creating list through powershell.

Thanks,
Sasi kumar Reddy