Powershell is great, powershell can do really great things if you know how to. So i would like to share some experiences with you.
Basic: Get the list and the item of your list:
[sourcecode language=”csharp”]
$Web = Get-SPWeb “http://server/sites/sitecollection”
$List = $Web.Lists[“Listname”]
//All items where ID is equal “1” you can set it as you like
$Item = $List.Items | ? {$_[“ID”] -eq “1”}
$groupcol = $Item[“YourField”]
[/sourcecode]
Reading the values of a lookup
[sourcecode language=”csharp”]
$ValueCollection = New-Object Microsoft.SharePoint.SPFieldUserValueCollection
foreach($group in $groupcol)
{
$group.lookupvalue
}
[/sourcecode]
Adding value to this field
[sourcecode language=”csharp”]
//This value collection will be saved afterwords into the field and it overrides the old values
$ValueCollection = New-Object Microsoft.SharePoint.SPFieldUserValueCollection
foreach($group in $groupcol)
{
//Add the old values to the new Value collection
$ValueCollection.Add($group)
$myGroup.id = “1”
$myGroup.Name = “Test”
$GroupValue = new-Object Microsoft.SharePoint.SPFieldUserValue($Web,
$myGroup.id, $myGroup.Name)
$ValueCollection.Add($GroupValue)
}
$Item[“YourField”] = $ValueCollection
$Item.Update()
[/sourcecode]
Hope this helps.
..:: I LIKE SHAREPOINT ::..