GUITACA BLOGS
Blogs from our authors

Office 365: The best recipes for developers
Gustavo Velez
Learn more and buy
Return to Blogs
Invoke-PnPQuery and Includes in SharePoint PnP PowerShell cmdletsGustavo Velez
Using SharePoint PnP PowerShell, I always forget the command-syntax to get a specific property from a SharePoint object, and how to commit changes when not using the Set family of cmdlets.20-09-2020
SharePoint

Includes - When you get an instance of a SharePoint object using PnP PowerShell for SharePoint, the return object does not contain all the property values. If you need the value of one specific property, use the -Includes parameter in the command, indicating the name of the property.

Invoke-PnPQuery - Executes queued actions in the same way as the Context.Load() plus Context.Execute() methods using the SharePoint Client Side Object Model (CSOM).

The next example script attempts to change the user experience for a List, moving it between Classic and Modern. Note the use of Includes and Invoke-PnPQuery.

$myCredential = Get-Credential
Connect-PnPOnline -Url "https://[domain].sharepoint.com/sites/[SiteName]" -Credentials $myCredential

# Get the List instance
$myList = Get-PnPList -Identity "Shared Documents" -Includes ListExperienceOptions

# Change the List User Experience (Values: 0=Auto, 1=Modern, 2=Classic)
$myList.ListExperienceOptions = 1
$myList.Update()
Invoke-PnPQuery

By the way, this is only an example, SharePoint PnP PowerShell contains the cmdlet to do this in a straightforward way. Use the cmdlet:

    Set-PnPList -ListExperience Auto

Were the ListExperience parameter can have the values Auto, NewExperience, or ClassicExperience.

Return to Blogs