Modify “Link”/ "HyperLink"/URL field using Powershell

Posted by KunaalKapoor on Geeks with Blogs See other posts from Geeks with Blogs or by KunaalKapoor
Published on Tue, 10 Jul 2012 21:36:16 GMT Indexed on 2012/07/11 3:17 UTC
Read the original article Hit count: 768

Filed under:
If you are trying to update a hyperlink/url type of column of a SharePoint list item using PowerShell and are getting the exception:
Unable to index into an object of type Microsoft.SharePoint.SPListItem.
At C:\mypowershell.ps1:39 char:10
+       $item[ <<<< "Website"] = $itemUrl      
    + CategoryInfo          : InvalidOperation: (RW_Website:String) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex

Then look no further :)

The url is basically stored like a simple string with url, description divided by comma.

So all you need to do is:

$myUrl = "http://www.google.com, Google"
$listitem["Link"] = $myUrl

That will, assuming "Link" is a type of "Hyperlink or Picture" (Hyperlink), create a link that says Google and links to http://www.google.com.

Also make sure you don't miss out on the 'http://' part as without that the value will not pass the SharePoint validation of allowed values.

© Geeks with Blogs or respective owner