Skip to content

Instantly share code, notes, and snippets.

@fluxdigital
Last active July 6, 2022 15:45
Show Gist options
  • Save fluxdigital/b83d787a00dff5fffe2f3719a65a1f84 to your computer and use it in GitHub Desktop.
Save fluxdigital/b83d787a00dff5fffe2f3719a65a1f84 to your computer and use it in GitHub Desktop.
<#
### Removes all existing SXA 'Draft' Sites ###
.Description
Finds all SXA Draft sites and deletes them.
#>
$sxaSites = Get-ChildItem -Path "/sitecore/content/Sites"
$successCount = 0
$failCount = 0
$siteGroupingPath = "Settings/Site Grouping"
$previewSiteName = "draft"
foreach ($sxaSite in $sxaSites) {
$siteItemPath = "$($sxaSite.Paths.FullPath)/$($siteGroupingPath)/$($sxaSite.Name)"
$previewSiteItemPath = "$($sxaSite.Paths.FullPath)/$($siteGroupingPath)/$($sxaSite.Name) $($previewSiteName)"
$siteItem = Get-Item -Path $siteItemPath -ErrorAction SilentlyContinue #Get the sitecore Item
$previewSiteItem = Get-Item -Path $previewSiteItemPath -ErrorAction SilentlyContinue #Get the sitecore Item
write-host "checking site path: $($siteItemPath)..."
if($siteItem -ne $null) #Check Site exists
{
write-host "found site: $($siteItemPath)" -ForegroundColor gray
}
write-host "checking preview site path: $($previewSiteItemPath)..."
if($previewSiteItem -ne $null) #Check if preview Site exists
{
write-host "exists: $($previewSiteItemPath) - removing" -ForegroundColor yellow
Remove-Item -Path $previewSiteItemPath -Force -Recurse -ErrorAction SilentlyContinue
}
else{
write-host "Preview Site Item not found: $($previewSiteItem.Name)" -ForegroundColor red
$successCount+=1
}
}
write-host "--- complete - successful: $($successCount) failed: $($failCount)---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment