Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |

Saturday, June 21, 2014

How To: Create view in SharePoint list using powershell

Below script will helps us on how to create view 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?
  5. Create single line of text field in SharePoint using powershell?
  6. Create mutli line of text field in SharePoint using powershell?
Download URL: Click here to download script 


Please correct the syntax as below for the scripts.
e.g:  Replace Name=""+ $fieldName +"" to Name='"+ $fieldName +"'  

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

$ViewName = "ViewName" 

$listname = "ListName"

$fieldName = "FieldName"

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

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

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

function Add-SPView([string]$listName, [string]$isActive)
{
  $OpenList = $docWeb.Lists[$listName]
  //To view only selected fields
  $viewFields = New-Object System.Collections.Specialized.StringCollection
  $viewFields.Add($ID)
  $viewFields.Add($Title)
  $viewFields.Add($isActive)   
  
  //Filter view based on choice field
  $viewQuery="MyChoice1"  
  $myListView = $OpenList.Views.Add($ViewName, $viewFields, $viewQuery, 100, $True, $False, “HTML”, $False)
  $myListView.Update()
}

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

write-Host "`n Creating View to the ACT Master lists `n"
Add-SPView -listName $listname -isActive IsActive

=============================================================================
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