List failed site designs with CLI for Microsoft 365

List failed site designs with CLI for Microsoft 365 header image

Roughly two years ago I blogged about listing all failed site designs with PowerShell. However, in a recent scenario I had to achieve the exact same thing but was looking at implementing it as a CLI for Microsoft 365. The goal was to achieve the same, a report of sites with failed site designs. The target however was to run it serverless.

CLI for Microsoft 365

The steps in the script are a lot like PowerShell:

  • List all sites in your tenant
  • List the site design for each site
  • Then list status information for each site design applied

The only real difference is that with the CLI for Microsoft 365 you can use JMESPath to filter down the results. It took a bit of fiddling to get the syntax right as filtering on numbers requires the correct use of quotes but in the end the script feels straightforward. The upside of this version is that you can run it on any device and even could run it on a Docker container.

Or as the ultimate goal for me, to orchestrate it using Logic Apps. That way you could schedule a report and get the results and errors posted to teams or to your action list. It might feal like a small sample, but automation of such reports could help you in keeping control over your environment. By proactively monitoring your sites you can act before a site owner might even be aware of potential issues.

$allSPOSites = m365 spo site classic list -o json | ConvertFrom-Json
$siteCount = $allSPOSites.Count

Write-Output "Processing $siteCount sites..."

foreach ($site in $allSPOSites) {
    $siteCounter++
    Write-Output "Processing $($site.Url)... ($siteCounter/$siteCount)"

    $runs = m365 spo sitedesign run list --webUrl $site.Url --output json | ConvertFrom-Json

    foreach($run in $runs) {
        $data = m365 spo sitedesign run status get --webUrl $site.Url --runId $run.ID --query '[?OutcomeCode == `1`]' --output json | ConvertFrom-Json

        if($data) {
            Write-Output "$($run.SiteDesignTitle) failed at $($site.Url) with id $($run.ID)"
        }
    }
}

Loading comments…