Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Populate ContentType when using Get-PnPListItem #1360

Closed
joshtransient opened this issue Nov 19, 2021 · 1 comment · Fixed by #1921
Closed

[FEATURE] Populate ContentType when using Get-PnPListItem #1360

joshtransient opened this issue Nov 19, 2021 · 1 comment · Fixed by #1921
Assignees
Labels
enhancement New feature or request

Comments

@joshtransient
Copy link

Is your feature request related to a problem? Please describe.
When I run Get-PnPListItem, the ContentType property is not populated, and I have to run Get-PnPProperty to retrieve it.

Describe the solution you'd like
I would like the ContentType property to contain data about the list item's content type when I run Get-PnPListItem.

Describe alternatives you've considered
My workaround involves storing the output of Get-PnPContentType in a variable, then getting a list item's content type ID through FieldValues and matching it up, e.g.

$list = Get-PnPList -Identity Documents
$listTypes = Get-PnPContentType -List $list
$items = Get-PnPListItem -List $list
foreach($item in $items) {
  [PSCustomObject]@{
    Path = $item['FileRef']
    Type = $listTypes.Where({ $_.Id.StringValue -eq $item['ContentTypeId'].StringValue }).Name
  }
}

Or, there is just making the direct REST call (don't shame me for using ArrayList):

$list = Get-PnPList -Identity Documents
$allItems = [System.Collections.ArrayList]::new()
$currentPageUrl = "/_api/Web/Lists(guid'{0}')/Items?`$select=FileRef&`$expand=ContentType" -f $list.id.Guid

do {
  $items = Invoke-PnPSPRestMethod -Method Get -Url $currentPageUrl
  $null = $allItems.AddRange(@($items.value))

  $currentPageUrl = $items.'odata.nextLink'
} while(-not [string]::IsNullOrEmpty($currentPageUrl))

Additional context
Pretty please.

@joshtransient joshtransient added the enhancement New feature or request label Nov 19, 2021
@gautamdsheth
Copy link
Collaborator

Correct me if I am wrong, but it should be possible if you specify it in ViewFields like here:

https://pnp.github.io/powershell/cmdlets/Get-PnPListItem.html#example-6

image

Here, in the ViewFields, you can specify ContentType and ContentTypeId and it should work as far as I know

@gautamdsheth gautamdsheth self-assigned this May 31, 2022
gautamdsheth added a commit to gautamdsheth/powershell that referenced this issue May 31, 2022
KoenZomers added a commit that referenced this issue Jun 9, 2022
Feature #1360 - fetch Content type info for list items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants