Monday, April 14, 2014

Add New Item to Link List in SharePoint using PowerShell

Here is my PowerShell script to add new item to SharePoint link list:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to add new item to SharePoint link list
Function Add-LinkListItem($WebURL, $ListName, $LinkURL, $LinkTitle)
        $ErrorActionPreference ="Stop" 

        #Get the Web
        $Web = Get-SPWeb $WebURL

        #Get the link list
        $List = $web.lists[$ListName]
        #Create a new item
        $NewItem = $list.Items.Add()
        #Add properties to this list item
        $NewItem["URL"] = "$($LinkURL), $($LinkTitle)"

        #Update the object so it gets saved to the list
        write-host “New Item has been Added to the List!"-foregroundcolor Green
    catch [System.SystemException]
        write-host "New Item Creation failed due to:" $_.Exception.Message -foregroundcolor Red
        #Dispose web object
        $ErrorActionPreference ="Continue" 

#Call the function to Add new list item
Add-LinkListItem "" "Quick Links" "" "Crescent Intranet"
and the output:
Add New Item to SharePoint Link list with PowerShell

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...