views:

1360

answers:

2

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.

+2  A: 

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

James Pogran
+1  A: 

Thanks James! That was very close and I'm thinking would work if I was specifying a single item?

Here's my full solution (with some extra bits):

$enumsite       = new-object microsoft.sharepoint.spsite($SubWebUrl)

foreach ($url in $enumsite.allwebs) 
{
    $NewItem = $MyList.Items.Add()  
    $NewItem["My Hyperlink Column"] = "$($url.url), $(url.title)"
    $NewItem.Update()
    }
$enumsite.Dispose()

Perhaps this will help someone else out in the future.

elorg