Sharepoint 2010 Create External List using Powershell

SharePoint 2010 has introduced a new type of List called External List.  The External List is used for displaying content that comes from Business Connectivity Services (BCS) Enterprise content types.  Business Connectivity Services is the replacement in SharePoint 2010 for The Business Data Catalog (BDC) in SharePoint 2007. 
External List needs External Content type for creating itself. External Content Type is created using either SharePoint Designer 2010 or Visual Studio 2010.  Once the External Content Type is created, you can create the external list either from the Create page in SharePoint or via SharePoint Designer or Powershell. 
Here is an example to create External List Using Powershell.

clear  
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue  
Add-PSSnapin Microsoft.SharePoint.Powershell $SiteUrl = "Site Url" $BusinessListName = "BusinessList"$ConfigListName = "Config"
$spweb = Get-SPWeb $SiteUrl
$ListGUID = ""
$ListUrl = "Lists/{0}"
  
  Write-Host "Creating and Configuring SPListDataSource"
  $ds = New-Object -TypeName Microsoft.SharePoint.SPListDataSource
  $ListCollection = $spweb.Lists
   
   $ds.SetProperty("LobSystemInstance", "Lob System Instance Name") #Info related to external content type   $ds.SetProperty("EntityNamespace", "Entity Namespace") #Info related to external content type   $ds.SetProperty("Entity", "Entity Name") #Info related to external content type   $ds.SetProperty("SpecificFinder", "Specific Finder")     
    Write-Host "Checking for list instance existence"
    $list =  $spweb.Lists[$BusinessListName];
      if($list)
      {
      Write-Host "List exists - " + $BusinessListName + " - deleting the list"
      $list.Delete();
      }
       
      Write-Host "Creating " + $BusinessListName + " list with Data Source.."
     
     $ListGUID = $spweb.Lists.Add($BusinessListName, "Description", "Title", $ds)     Write-Host $ListGUID
     $ListCollection[$ListGUID].Update();
     $spweb.Update();                      Write-Host "List created successfully.." + 
     $list =  $spweb.Lists[$ConfigListName];
     if($list)
     {
     Write-Host "List exists - Config - deleting the list"
     $list.Delete();
     }

External List supports CRUD functionality means you can Create, Read, Update and Delete data all the way back to the data source.

Comments

Post a Comment

Popular posts from this blog

C# Copy files from one server to another

Export SharePoint Online Group Users to Excel using Powershell

Suppress StyleCop SA1600