What is the correct powershell syntax for finding all list items in a given list where a Person field matches a user retrieved from Get-SPUser?


$user = Get-SPUser -web *web* -Identity *domain\user*

$listItems = $web.Lists["*listName*"].Items | Where-Object $_.["*personField*"] -eq $user

Here's something I wrote for another project:

Function Convert-SPFieldUserValueToSPUser {
    param (
        [Microsoft.SharePoint.SPListItem] $item,
        [string] $fieldName

    ($item.Fields[$fieldName]).GetFieldValue($item[$fieldName]).User | Write-Output

Then, you can use this function as follows:

$userLogin = '*domain\user*';
$listItems = $web.Lists["*listName*"].Items | `
    Where-Object (($_ | Convert-SPFieldUserValueToSPUser -field "*personField*").LoginName -eq $userLogin);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.