PowerShell Get SharePoint Person or Group Field

This one drove me CRAZY!

Simple question, how do you get people or groups from a SharePoint People or Group field.

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$site = Get-SPweb "http://www.sharepointed.com"

				$mList=$site.Lists["ListName"]
                                #you will want to provide a valid ID here:
				$item = $mList.GetItemById(<strong>"4"</strong>)
				$users=$item["MyPersonOrGroupField"]
				
				#build array of our Person or Groups
				$PeopleOrGroup = New-Object System.Collections.ArrayList
				
				If($PeopleOrGroup.Count -ge 0)
				{
					foreach($blah in $PeopleOrGroup)
						{
						 $parseUsr = $blah.ToString().Split('#')[1]
						 $PeopleOrGroup.add($parseUsr)					 
						}
				}

                                #now if you want to access our newly created array
                                Foreach($pg in $PeopleOrGroup)
                                {
                                     write-host $pg
                                }
                                


*Update*
Found another way to get this done!

foreach($blah in $PeopleOrGroup)
       {
	 $PeopleOrGroup.add($site.Users.GetByID($blah.LookupId))					 
       }

Leave a Reply

Your email address will not be published. Required fields are marked *