In this SharePoint tutorial, we will discuss various SharePoint PnP PowerShell examples. Here we will see the below PnP PowerShell SharePoint examples:
- Create modern team site using PnP PowerShell (with Office 365 group)
- How to create a modern team site without an office 365 group using PnP PowerShell
- PnP PowerShell get all modern team sites
- Remove a Modern SharePoint Team Site using PnP PowerShell
- How to remove modern SharePoint Team Site (with Site URL) with Force
- Remove Modern SharePoint Team Site (with Site URL) from the Recycle Bin
- Create a SharePoint Online Communication Site using PnP PowerShell
- Get all Communication Site using PnP PowerShell
- Delete a Communication Site Using PnP PowerShell
- Delete a SharePoint Communication Site (with Site URL) with Force
- Delete the SharePoint Communication Site (with Site URL) from the Recycle Bin
- Get SharePoint site created date using PnP PowerShell
- PnP PowerShell add user to sharepoint group
- PnP PowerShell add user as site collection administrator
- Get SharePoint Site Collection Administrator using PnP PowerShell
- Remove Site Collection Administrator SharePoint Online using PnP PowerShell
- How to Get all Site Collections in SharePoint Online Using PnP PowerShell
- Get all Sub Sites in SharePoint Online Using PnP PowerShell
- Restore SharePoint Online Site Using PnP PowerShell
- Create a SharePoint Online List using PnP PowerShell
- Check if SharePoint Online List exists or not using PnP PowerShell
- How to Remove SharePoint Online List using PnP PowerShell
- Remove SharePoint Online List with Force
- Remove SharePoint Online List with Recycle bin
- Retrieve a SharePoint Online List using PnP PowerShell
- How to update SharePoint Online List Title Using PnP PowerShell
If you are new to PnP PowerShell, check out an article on Connect to SharePoint online using pnp PowerShell.
SharePoint PnP PowerShell Examples
Now, let us see various SharePoint PnP PowerShell examples, especially related to SharePoint sites and lists and libraries. All these PowerShell commands you can run in Windows PowerShell ISE.

1. Create modern team site using PnP PowerShell (with Office 365 group)
Now, we will see how to create a SharePoint Online modern team site using PnP PowerShell. This will be an Office 365 group connected team site in SharePoint.
Below is the PowerShell script to create modern team site using pnp powershell.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
New-PnPSite -Type TeamSite -Title 'TSInfo Modern Team' -Alias "TSInfoModernTeam" -IsPublic
Write-Host "The modern team site has been created successfully."

Once you run the command, you can see the team site get created which is available in Active sites on SharePoint Online admin center.

2. Create a modern team site without an office 365 group using PnP PowerShell
We can easily create a modern team site without an Office 365 group using PnP PowerShell in SharePoint Online.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
New-PnPTenantSite `
-Title "TSInfo Modern Team Without Group" `
-Url "https://tenant.sharepoint.com/sites/TSInfoModernTeamWithoutGroup" `
-Description "Modern Site" `
-Owner "preeti@tenant.onmicrosoft.com" `
-Lcid 1033 `
-Template "STS#3" `
-TimeZone 10 `
-Wait
Write-Host "The modern team site without Office 365 Group has been created successfully."

Once you run the PowerShell cmdlet, you can see in the Active Sites tab, the SharePoint Online team site without an Office 365 group.

This is how to create a team site using PnP PowerShell (without an Office 365 group).
3. PnP PowerShell get all modern team sites
Now, we will see how to get all modern team sites in SharePoint Online using PnP PowerShell.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Get-PnPTenantSite -Template GROUP#0
Write-Host "Retrieved all Modern Team Sites."

4. Remove a Modern SharePoint Team Site using PnP PowerShell
Below is the PnP PowerShell command to remove a modern SharePoint Team Site Collection from your Office 365 tenant.
NOTE:
Before removing the Modern Team Site from your office 365 tenant, You must ensure to delete the SharePoint Office 365 Group which will be present with the same existing Modern Team Site name.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Remove-PnPTenantSite -Url https://tenant.sharepoint.com/sites/TSInfoModernTeam
Write-Host "SharePoint Online Team Site is Removed."
Once you will run the above PowerShell script, then a pop-up window will appear to ensure to delete the Modern SharePoint Team Site.

When you will click on the Yes button, then the Modern SharePoint Team Site will remove as shown in the below screenshot.

Now when you will go to the SharePoint Deleted sites in the SharePoint Online admin center, you can see the deleted SharePoint Modern Site like below.
Now, you can see the TSInfo Modern Team Site in Deleted sites.

This is how to delete a modern team site using PnP PowerShell.
Check out, SharePoint site owner training.
5. Remove Modern SharePoint Team Site (with Site URL) with Force
This below PnP PowerShell Code will remove the Modern SharePoint Team Site with the Site URL (https://tenant.sharepoint.com/sites/TSInfoModernTeam) with force and it will skip the recycle bin.
Remove-PnPTenantSite -Url https://tenant.sharepoint.com/sites/TSInfoModernTeam -Force -SkipRecycleBin
6. Remove Modern SharePoint Team Site (with Site URL) from the Recycle Bin
This below PnP PowerShell cmdlets will remove the Modern SharePoint Team Site with the Site URL (https://tenant.sharepoint.com/sites/TSInfoModernTeam) from the Recycle bin.
Remove-PnPTenantSite -Url https://tenant.sharepoint.com/sites/TSInfoModernTeam -FromRecycleBin
7. Create a SharePoint Online Communication Site using PnP PowerShell
We can use PnP PowerShell commands to create a SharePoint Online communication site. Below is the PowerShell cmdlets to create a communication site in SharePoint Online.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
New-PnPSite -Type CommunicationSite -Title 'TSInfo Communication Site' -Url "https://tenant.sharepoint.com/sites/TSInfoCommunicationSite" -SiteDesign "Showcase"
Write-Host "The communication site has been created successfully.

If you will check in the SharePoint Online Admin center, you can see the communication sites appears under Active Sites.

This is how to create a sharepoint communication site using pnp powershell.
8. Get all Communication Site using PnP PowerShell
Below is the PowerShell script to get all communication sites using pnp powershell from Office 365.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Get-PnPTenantSite -Template SITEPAGEPUBLISHING#0
Write-Host "Retrieved all Communication Sites."

This is how to get all communication sites using pnp powershell.
9. Delete a Communication Site Using PnP PowerShell
Below is the PowerShell script to delete a Communication Site from Office 365 tenant using PnP PowerShell.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Remove-PnPTenantSite -Url https://tenant.sharepoint.com/sites/TSInfoCommunicationSite
Write-Host "SharePoint Online Communication Site is Removed."
Once you run the script, a pop-up window will appear to confirm to delete the SharePoint Communication Site.

When you will click on the Yes button, then the SharePoint Communication Site will remove as shown in the below screenshot.

Now when you will go to the SharePoint Deleted sites, then you can see your deleted SharePoint Communication Site will be there as like below.
As I have removed the TSInfo Communication Site, So it is showing in my SharePoint Deleted sites page.

This is how to delete a communication site using PnP PowerShell in Office 365.
10. Delete a SharePoint Communication Site (with Site URL) with Force
This below PnP PowerShell Code will delete the Communication Site with the Site URL (https://tenant.sharepoint.com/sites/TSInfoCommunicationSite) with force and it will skip the recycle bin.
Remove-PnPTenantSite -Url https://tenant.sharepoint.com/sites/TSInfoCommunicationSite -Force -SkipRecycleBin
11. Delete the SharePoint Communication Site (with Site URL) from the Recycle Bin
This below PnP PowerShell Code will delete the SharePoint Communication Site with the Site URL (https://tenant.sharepoint.com/sites/TSInfoCommunicationSite) from the Recycle bin.
Remove-PnPTenantSite -Url https://tenant.sharepoint.com/sites/TSInfoCommunicationSite -FromRecycleBin
12. Get SharePoint site created date using PnP PowerShell
By using PnP PowerShell cmdlets, we can easily get created date of a SharePoint Online site.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/tsinfoclassic/" -Credentials $cred
$web=Get-PnPWeb -Includes Created
write-host $web.Created

This is how to get SharePoint Online site created date using PnP PowerShell.
13. PnP PowerShell add user to sharepoint group
Now, we will check how to add user to SharePoint group using PnP PowerShell.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
$siteURL= "https://tenant.sharepoint.com/sites/tsinfoclassic/"
Connect-PnPOnline -Url $siteURL -Credentials $cred
Add-PnPUserToGroup -LoginName Bijay@tenant.onmicrosoft.com -Identity 'TSInfoGroup'
Write-Host "A user is added to the SharePoint Group."

Once you run the script, you can see the user to the SharePoint group in the SharePoint Online site.

This is how to add user to sharepoint group using pnp powershell.
14. PnP PowerShell add user as site collection administrator
Now, we will see how to add site collection administrator’s to SharePoint Online list using PnP PowerShell.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Add-PnPSiteCollectionAdmin -Owners @("preeti@tenant.onmicrosoft.com", "bijay@tenant.onmicrosoft.com")
Write-Host "Added additional Site Collection Administrator."

This is how to add user as site collection administrator using pnp powershell.
15. Get SharePoint Site Collection Administrator using PnP PowerShell
Below is the PowerShell cmdlets to get the site collection administrators using PnP PowerShell in SharePoint Online Office 365.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Get-PnPSiteCollectionAdmin
Write-Host "Retrieved Site Collection Administrator."

This is how to get sharepoint site collection administrator using PnP PowerShell.
16. Remove Site Collection Administrator SharePoint Online using PnP PowerShell
Now, we will see how to remove SharePoint site collection administrator usng PnP PowerShell in SharePoint Online Office 365.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Remove-PnPSiteCollectionAdmin -Owners @("preeti@tenant.onmicrosoft.com", "bijay@tenant.onmicrosoft.com")
Write-Host "Removed site collection owners from the site collection in the current context."

This below PnP PowerShell command will help you to remove all existing site collection administrators from the SharePoint site collection.
Get-PnPSiteCollectionAdmin | Remove-PnPSiteCollectionAdmin
17. Get all Site Collections in SharePoint Online Using PnP PowerShell
Now, we will see how to get site collections in SharePoint Online using pnp PowerShell.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Get-PnPTenantSite
Write-Host "Retrieved all Site Collections."

This is how to get SharePoint site collections using PnP PowerShell.
18. Get all Sub Sites in SharePoint Online Using PnP PowerShell
If you want to get all the sub sites from a SharePoint Online site collection using PnP PowerShell.
Below is the PnP PowerShell script to get all sub sites in SharePoint Online site collection.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
$siteURL= "https://tenant.sharepoint.com/sites/SharePointSky/"
Connect-PnPOnline -Url $siteURL -Credentials $cred
Get-PnPSubWebs
Write-Host "All the Sub Sites are retrieved from SharePoint Online."

This is how to get all Sub Sites in SharePoint Online using PnP PowerShell.
19. Restore SharePoint Online Site Using PnP PowerShell
Below is the PnP PowerShell script to restore a SharePoint Online site using PnP PowerShell.
$userName = "preeti@tenant.onmicrosoft.com"
$passWord = "**********"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord
$DeletedSiteURL= "https://tenant.sharepoint.com/sites/TSInfoModernTeam"
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -Credentials $cred
Restore-PnPTenantRecycleBinItem -Url $DeletedSiteURL -Force -ErrorAction Stop
Write-Host "The SharePoint Deleted Site has been restored successfully."


This is how to restore a SharePoint site using pnp powershell.
20. Create a SharePoint Online List using PnP PowerShell
Now, we will see how to create a SharePoint Online List using PnP PowerShell. Below represents the PowerShell command:
$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
$listName="TSInfoTeam"
New-PnPList -Title $listName -Url "TSInfoTeam" -Template GenericList
Write-Host ("SharePoint List is created")

When you run the above PnP PowerShell command, then you can see the SharePoint Online list will create which is available in the Site Content of the SharePoint Online Site.

This is how to create a list using PnP PowerShell.
21. Check if SharePoint Online List exists or not using PnP PowerShell
If you want to check if the SharePoint Online List exists in your SharePoint Site or not, then follow the below PnP PowerShell command:
$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
$listName="TSInfoTeam"
if($listName)
{
write-Host ("SharePoint List is already exists")
}
else
{
Connect-PnPOnline -Url $siteurl -Credentials $cred
New-PnPList -Title $listName -Url "TSInfoTeam" -Template GenericList
Write-Host ("SharePoint List is created")
}
Once you will run the command, then it will let you know if the SharePoint exists or not.

22. Remove SharePoint Online List using PnP PowerShell
We can easily remove a SharePoint Online list from SharePoint site collection using the PnP PowerShell command.
$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
$listName="TSInfoTeam"
Remove-PnPList -Identity $listName
Write-Host ("SharePoint List is Removed")
Once you will run the above command, then it will ask you to ensure to delete the SharePoint list as shown below.

When you will click on Yes, then the SharePoint Online List will remove.

This is how to delete a SharePoint list using PnP PowerShell.
23. Remove SharePoint Online List with Force
Similarly, if you will run the below PnP PowerShell command, then the SharePoint list will remove forcefully without asking the confirmation.
Remove-PnPList -Identity $listName -Force

24. Remove SharePoint Online List with Recycle bin
When you will run the below PnP PowerShell command, then it will ask you to ensure to delete the SharePoint Online List.
Remove-PnPList -Identity $listName -Recycle

Once you clicked on Yes button, then the SharePoint Online List will remove and it will move to the Recycle bin as like the below screenshot.

25. Retrieve a SharePoint Online List using PnP PowerShell
Below is the PnP PowerShell command to retrieve the SharePoint Online List from your SharePoint Online Site.
$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
Get-PnPList -Identity 486ee331-e38f-4d89-82cf-8e0bef45d853
Write-Host ('SharePoint List is Retrieved with Id')
Get-PnPList -Identity Lists/TSInfoTeam
Write-Host ('SharePoint List is Retrieved with URL')
When you will run the command, then you will get your SharePoint Online List with List Title, Id and Url as shown below.

This is how to get SharePoint Online list using PnP PowerShell.
26. Update SharePoint Online List Title Using PnP PowerShell
Suppose you want to update your SharePoint Online List Title with a new title name, then you can do it by using PnP PowerShell command.
Here in the below screenshot, my SharePoint List Title is TSInfoTeam. I want to update this List Title as TSInfoGroup.

Follow this below PnP PowerShell command to update the SharePoint Online List Title.
$cred= Add-PnPStoredCredential -Name https://tenant.sharepoint.com -Username preeti@tenant.onmicrosoft.com -Password (ConvertTo-SecureString -String "**********" -AsPlainText -Force)
$siteurl="https://tenant.sharepoint.com/sites/TSInfoClassic"
Connect-PnPOnline -Url $siteurl -Credentials $cred
$listName="TSInfoTeam"
Set-PnPList -Identity $listName -Title 'TSInfoGroup' -Description 'This SharePoint List is used for TSInfo'
Write-Host ('SharePoint List title is updated')

Once the above command will run and finish, go to that SharePoint Online List and just refresh that page. Then you can see the title has been updated as shown in the below screenshot.

As I have also updated the SharePoint Online List Description, you can see the updated description in the List Settings page as like below.

This is how to update SharePoint list title using PnP PowerShell.
You may like the following PowerShell tutorials:
- How to connect to Microsoft Teams using PowerShell
- PowerShell Copy Item examples
- Create SharePoint Online Modern Page
- SharePoint Online regional settings
- Delete SharePoint Site + PowerShell
I hope you liked the sharepoint pnp powershell examples. We covered the below examples.
- How to create a modern team site using PnP PowerShell (with Office 365 group)
- How to create a modern team site without an office 365 group using PnP PowerShell
- PnP PowerShell get all modern team sites
- How to remove a Modern SharePoint Team Site using PnP PowerShell
- How to remove modern SharePoint Team Site (with Site URL) with Force
- Remove Modern SharePoint Team Site (with Site URL) from the Recycle Bin
- Create a SharePoint Online Communication Site using PnP PowerShell
- Get all Communication Site using PnP PowerShell
- Delete a Communication Site Using PnP PowerShell
- How to delete a SharePoint Communication Site (with Site URL) with Force
- Delete the SharePoint Communication Site (with Site URL) from the Recycle Bin
- Get SharePoint site created date using PnP PowerShell
- PnP PowerShell add a user to sharepoint group
- PnP PowerShell add a user as site collection administrator
- Get SharePoint Site Collection Administrator using PnP PowerShell
- Remove Site Collection Administrator SharePoint Online using PnP PowerShell
- How to Get all Site Collections in SharePoint Online Using PnP PowerShell
- Get all Sub Sites in SharePoint Online Using PnP PowerShell
- How to restore SharePoint Online Site Using PnP PowerShell
- Create a SharePoint Online List using PnP PowerShell
- Check if SharePoint Online List exists or not using PnP PowerShell
- How to Remove SharePoint Online List using PnP PowerShell
- Remove SharePoint Online List with Force
- Remove SharePoint Online List with Recycle bin
- Retrieve a SharePoint Online List using PnP PowerShell
- How to update SharePoint Online List Title Using PnP PowerShell
I am Bijay a Microsoft MVP (8 times –Â My MVP Profile) in SharePoint and have more than 15 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com