Managing SharePoint Sites and Lists
Once connected with Connect-PnPOnline, you can create and manage SharePoint sites, lists, and columns entirely from PowerShell.
Getting Site Information
Retrieve details about the site you are connected to:
Get-PnPSite # Returns the site collection object
Get-PnPWeb # Returns the current web (subsite) object
Get-PnPWeb | Select-Object Title, Url, LanguageKey Concept: In SharePoint, a site collection (returned by Get-PnPSite) is the top-level container. A web (returned by Get-PnPWeb) is an individual site or subsite within that collection.
Creating New Sites
Use New-PnPSite to create communication or team sites. The -Type parameter controls which kind:
# Communication site
New-PnPSite -Type CommunicationSite -Title "Company News" `
-Url "https://contoso.sharepoint.com/sites/CompanyNews"
# Team site (backed by an M365 Group)
New-PnPSite -Type TeamSite -Title "Engineering" -Alias "Engineering"Communication sites are for broadcasting content. Team sites are collaboration spaces tied to a Microsoft 365 Group.
Working with Lists
Lists are the core data structure in SharePoint. Retrieve, create, and remove them with these cmdlets:
# Get all lists on the current site
Get-PnPList
# Get a specific list by title
Get-PnPList -Identity "Projects"
# Create a new generic list
New-PnPList -Title "Inventory" -Template GenericList
# Create a document library
New-PnPList -Title "Proposals" -Template DocumentLibraryAdding Columns (Fields)
After creating a list, add custom columns with Add-PnPField:
Add-PnPField -List "Inventory" -DisplayName "SKU" `
-InternalName "SKU" -Type Text
Add-PnPField -List "Inventory" -DisplayName "Quantity" `
-InternalName "Quantity" -Type NumberKey Concept: Always specify both -DisplayName (what users see) and -InternalName (used in code and queries). The internal name cannot be changed after creation, so choose it carefully.
Removing a List
To delete a list, use Remove-PnPList. Add -Force to skip the confirmation prompt:
Remove-PnPList -Identity "Inventory" -ForceExercises
Write a command to get the current SharePoint web and display only its Title and Url properties.