Below script will helps us on how to create view in SharePoint using PowerShell. please refer 
my previous posts on below scenarios:
Please correct the syntax as below for the scripts.
e.g: Replace Name=""+ $fieldName +"" to Name='"+ $fieldName +"'
Thanks,
Sasi Kumar Reddy
- Create a new list in SharePoint using powershell?
 - Check whether the list exits or not?
 - Create a new field in SharePoint list using powershell
 - Add items to the list in SharePoint using powershell?
 - Create single line of text field in SharePoint using powershell?
 - Create mutli line of text field in SharePoint using powershell?
 
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