Skip to content

Get-Sites-Query

SharePoint Online: Query site collections

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

[CmdletBinding()]
Param(
    [int]$Limit = 200
)

Process {
    try {
        $cmdArgs = @{ ErrorAction = 'Stop'; Limit = $Limit }
        $result = Get-SPOSite @cmdArgs | Select-Object Url, Title | Sort-Object Title
        foreach ($item in $result) {
            [PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; Value = $item.Url; DisplayValue = $item.Title }
        }
    }
    catch { throw }
}

Maximum number of site collections to return

An interactive directory of PowerShell scripts.