List Items and Content Types
SharePoint lists store rows of data called list items. Each item has fields (columns) that hold values. PnP PowerShell gives you full CRUD (Create, Read, Update, Delete) control over list items.
Reading List Items
Retrieve all items from a list:
Get-PnPListItem -List "Projects"For large lists, use a CAML query with the -Query parameter to filter server-side and improve performance:
$query = "<View><Query><Where>
<Eq><FieldRef Name='Status'/><Value Type='Text'>Active</Value></Eq>
</Where></Query></View>"
Get-PnPListItem -List "Projects" -Query $queryKey Concept: CAML (Collaborative Application Markup Language) is SharePoint's XML-based query language. Using -Query filters data on the server, which is far more efficient than retrieving all items and filtering locally with Where-Object.
Adding New Items
Create a new list item by passing a hashtable of field values:
Add-PnPListItem -List "Projects" -Values @{
Title = "Website Redesign"
Status = "Active"
Priority = "High"
}Updating Items
Update an existing item by its ID:
Set-PnPListItem -List "Projects" -Identity 5 -Values @{
Status = "Completed"
}Deleting Items
Remove a list item by ID. Use -Force to skip confirmation:
Remove-PnPListItem -List "Projects" -Identity 5 -ForceContent Types
Content types define reusable sets of columns and behaviors. View available content types with:
Get-PnPContentTypeTo see content types specific to a list:
Get-PnPContentType -List "Projects"Adding Content Types to Lists
Apply an existing site content type to a list:
Add-PnPContentTypeToList -List "Projects" `
-ContentType "Document" -DefaultContentTypeKey Concept: The -DefaultContentType switch makes the added content type the default for new items. Without it, the content type is available but not pre-selected when users create items.
Exercises
Write a CAML query command to get items from the 'Tickets' list where the Priority field equals 'High'. Store the CAML XML in a $query variable, then pass it to Get-PnPListItem.