Add a "Hyperlink" item type to a list using PowerShell in Sharepoint

elorg picture elorg · Apr 10, 2009 · Viewed 7.9k times · Source

I've been a SharePoint admin for a while, and now have been tasked with a bit more of a developer role - which I'm still very much learning. Most things I've been able to figure out on my own or through Google, but this one has me stumped.

For one particular task I need to use PowerShell to script adding items to a list. Normally - not a difficult task. These steps are all over the web. However, I have yet to find anywhere that will tell you how to add a "Hyperlink" type of item to a list.

I can add one using the following code:

$NewItem = $MyList.Items.Add()  
$NewItem["My Hyperlink Column"] = $($url.url)  
$NewItem.Update()  

But I want to set the name/title of the link as well and that's what stumps me. I don't want to have to create a separate column in the list and populate that with the link name, and use code similar to above to populate the url/link.

Answer

James Pogran picture James Pogran · Apr 10, 2009

Does this work for you? I don't have a Sharepoint install available to test on, this is from memory:

$NewItem = $MyList.Items.Add()  
$NewItem["My Hyperlink Column"] = "$($url.url), <Title>"
$NewItem.Update()

james