Home >Tips >PowerShell with SharePoint from Scratch >Create and remove communication sites kalmstrom.com site map icon Site map  

Remove SharePoint Sites

A PowerShell with SharePoint tutorial

PowerShell iconIn the previous article, Peter Kalmström created a communication site, the root site of a site collection, for each of the departments in an array. He used a forEach loop for the site creation.

In this article, he will instead use a forEach loop to run through the same array and remove all the sites. He does not want to have any confirmation messages, and he does not want the sites to be sent to the recycling bin.

These are the changes Peter has to make in the forEach loop that created the sites:
  • Replace the progress message text and color.
  • Replace the last row before the end curly bracket with the cmdlet Remove-PnPSite and the parameters Url, Force and SkipRecycleBin.
foreach($Dep in $Departments){
    $SiteURL = "PATH" + $Dep
    Write-Host ($SiteURL + " is being removed ...") -ForegroundColor Red
    Remove-PnPTenantSite -Url $SiteURL -Force -SkipRecycleBin 
}





back icon next icon
Products Buy FAQ Services Tips Books Contact About Us Tools

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved