Share Point 2010 Create Links List using Power Shell

Links List in share point 2010 is list that contains links for reference with description means it stores urls along with details.

For example
If we need to store some data like
Data1:             Url- www.google.com              Description- Here is a link for google
Data2:             Url- www.blogger.com              Description- Here is a link for blogger



clear
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue  
Add-PSSnapin Microsoft.SharePoint.Powershell 

function CreateandAdd-SPLinkListItems
{
    param($siteCollectionUrl, $listTitle, $itemDescription, $itemUrl) 
    $site =new-object Microsoft.SharePoint.SPSite($siteCollectionUrl)
    $web = $site.OpenWeb("")
    
    $list=$web.Lists.TryGetList($listTitle)
    
    if($list -eq $null)
    { 
    $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::Links
    $web.Lists.Add($listTitle,”Desc of the List”,$listTemplate)
    write-host “List added in the Web : ” $spweb -foregroundcolor Green   
    }

    $list = $web.Lists[$listTitle]
    $item = $list.Items.Add()
    $urlValue = New-Object Microsoft.SharePoint.SPFieldUrlValue("")
    $urlValue.Description = $itemDescription;
    $urlValue.Url =  $itemUrl
    $item["URL"] = $urlValue
    $item.update()
    $List.update()
    $web.Dispose()
    $site.Dispose()
}


CreateandAdd-SPLinkListItems "Site Url" "Links List for Info" "Here is a link for google" "http://www.google.com"
CreateandAdd-SPLinkListItems "Site Url" "Links List for Info" "Here is a link for blogger" "http://www.blogger.com"

Comments

Popular posts from this blog

C# Copy files from one server to another

Export SharePoint Online Group Users to Excel using Powershell