I've the following code to retrieve list items and select properties:

$list = $web.Lists["MyCustomList"]
$listItems = $list.GetItems()
$items = $listItems | select "MyCustomFieldName"

This does not work tho (I've tried with ex. 'Title' and it works), how could I retrieve the custom field? If I do the following, it gives me the value:


Don't ask me to explain how this works, but try:

$items = $listItems | select @{ Label="MyCustomFieldName";Expression={$_["MyCustomFieldName"]}}

or an alternate, if you don't mind looping instead of using select:

 $items = $listItems | % { $_["MyCustomFieldName"] }

Credit: https://stackoverflow.com/a/27373810/1452528


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.