Skip to content

Test-Site

SharePoint Online: Tests a site collection

#Requires -Version 5.1
#Requires -Modules Microsoft.Online.SharePoint.PowerShell

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$Identity,
    [string]$RuleId,
    [switch]$RunAlways
)

Process {
    try {
        $cmdArgs = @{ ErrorAction = 'Stop'; Identity = $Identity; RunAlways = $RunAlways }
        if (-not [System.String]::IsNullOrWhiteSpace($RuleId)) { $cmdArgs.Add('RuleId', $RuleId) }
        $result = Test-SPOSite @cmdArgs | Select-Object *
        if ($null -ne $result) { foreach ($item in $result) { $item | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force } }
    }
    catch { throw }
}

URL of the site collection to test

Specific health check rule to run

Off

Display what would happen instead of executing

An interactive directory of PowerShell scripts.