Recently, I was working on an automation script to create a SharePoint site. There, I wanted to check if a SharePoint site already exists. In this tutorial, I will show you how to check if a SharePoint site exists using PnP PowerShell.
Check if a SharePoint Site Exists using PnP PowerShell using Get-PnPTenantSite
I will show how to to check if a site exists in SharePoint using PnP PowerShell using Get-PnPTenantSite PnP PowerShell cmdlet.
In PnP PowerShell, you can use the Get-PnPTenantSite cmdlet to check if a site exists in SharePoint Online. The Get-PnPTenantSite cmdlet allows you to retrieve site collections from the tenant. You can use this cmdlet to check if a specific site exists.
Here is an example.
Connect-PnPOnline -Url "https://szg52.sharepoint.com" -Interactive
$siteUrl = "https://szg52.sharepoint.com/sites/accounting"
$site = Get-PnPTenantSite -Url $siteUrl -ErrorAction SilentlyContinue
if ($site) {
Write-Output "The site 'accounting' exists."
} else {
Write-Output "The site 'accounting' does not exist."
}Since, in my tenant, there no site available as “accounting”, it shows output like “The site ‘accounting’ does not exist.”. You can check in the screenshot below.

You can also use the Where with the Get-PnPTenantSite cmdlet like below:
Connect-PnPOnline -Url "https://szg52.sharepoint.com" -Interactive
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
$site = Get-PnPTenantSite | Where {$_.Url -eq $SiteURL}
if ($site) {
Write-Output "The site 'PowerShellFAQs' exists."
} else {
Write-Output "The site 'PowerShellFAQs' does not exist."
}This is how to check if a SharePoint Online site exists or not using PnP PowerShell.
I hope this helps.
You may also like:
- How to Check if a List Exists in SharePoint Site using PnP PowerShell?
- Get All SharePoint Online Sites using PnP PowerShell
- Enable Custom Script in SharePoint Online Using PnP PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.