Answered by:
update person/group field in powershell, with a group name

Question
-
Hi,
I need to update a person column in my library through powershell, I can do this for a single user, but how do update the value to be a sharepoint group? the column has been set correctly to allow groups, and I can set the group name if I use the browser. but I cant do it through powershell. I get "Invalid data has been used to update the list item"
Thanks,
Thursday, November 13, 2014 5:56 PM
Answers
-
Hi Craig,
It seems you are trying to assign Role into people and group column. That's why it is throwing error. Try assigning group into that column.
$web = get-spweb https://mysite/myweb $groups = $web.Groups $GroupName = $groups["GroupName"] foreach($list in $web.Lists) { if($list.BaseType -eq "DocumentLibrary") { $items = $list.Items foreach ($item in $items) { if($item.File.CheckOutType -eq "None"){ $item.File.CheckOut() $item["Document Advisor"]= $GroupName $item.Update() $item.File.CheckIn("Admin") Write-Host "updating document: "$item["Title"] } } } }
I've tried to modify your code please check it.
Hope this will help to resolve your problem.
Best Regards,
Brij K
- Marked as answer by Craig-Taylor Friday, November 14, 2014 4:27 PM
Thursday, November 13, 2014 11:21 PM
All replies
-
Hi Craig,
Can you share your powershell script.
Regards,
Brij KThursday, November 13, 2014 6:10 PM -
Hi,
$web = get-spweb https://mysite/myweb $RA = $web.RoleAssignments $GroupName = $RA | ?{$_.Member -like "*Champion*" } |?{$_.RoleDefinitionBindings.Name -like "*section*"}|?{$_.Member -notlike "*Global*"}|Select-Object -ExpandProperty Member | select -ExpandProperty Name foreach($list in $web.Lists) { if($list.BaseType -eq "DocumentLibrary") { $items = $list.Items foreach ($item in $items) { if($item.File.CheckOutType -eq "None"){ $item.File.CheckOut() $item["Document Advisor"]= $GroupName $item.Update() $item.File.CheckIn("Admin") Write-Host "updating document: "$item["Title"] } } } }
Thursday, November 13, 2014 6:37 PM -
Hi Craig,
It seems you are trying to assign Role into people and group column. That's why it is throwing error. Try assigning group into that column.
$web = get-spweb https://mysite/myweb $groups = $web.Groups $GroupName = $groups["GroupName"] foreach($list in $web.Lists) { if($list.BaseType -eq "DocumentLibrary") { $items = $list.Items foreach ($item in $items) { if($item.File.CheckOutType -eq "None"){ $item.File.CheckOut() $item["Document Advisor"]= $GroupName $item.Update() $item.File.CheckIn("Admin") Write-Host "updating document: "$item["Title"] } } } }
I've tried to modify your code please check it.
Hope this will help to resolve your problem.
Best Regards,
Brij K
- Marked as answer by Craig-Taylor Friday, November 14, 2014 4:27 PM
Thursday, November 13, 2014 11:21 PM -
Hi Thanks for this, I do still need the role assignments bit as the group name is slightly different for each site in the collection that I want to update. so I first need to 'get' the group name, then I can use the code you gave to do the rest.
I have tested and all works well now.
Thanks,
Friday, November 14, 2014 4:26 PM