Skip to content

/flags/sharepoint-online/get-sposite-includepersonalsite

Get-SPOSite -IncludePersonalSite $true: include OneDrive sites in the list

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
SharePoint Online PowerShell
command
Get-SPOSite
flag
-IncludePersonalSite $true
default
$false (OneDrive sites are not returned)

Get-SPOSite -IncludePersonalSite $true adds OneDrive (personal) sites to the output of Get-SPOSite. By default they are excluded: the reference says "The values are $true and $false. By default, the value is $false which means no personal sites will be returned." Combine it with -Limit All, because OneDrive sites usually outnumber SharePoint sites and the default limit of 200 is reached quickly.

powershell
Connect-SPOService -Url https://contoso-admin.sharepoint.com
Get-SPOSite -IncludePersonalSite $true -Limit All `
  -Filter "Url -like '-my.sharepoint.com/personal/'" |
  Select-Object Url, Owner, StorageUsageCurrent

A Boolean, not a switch

Unlike most "include" options in PowerShell, this parameter is a nullable Boolean. Writing -IncludePersonalSite without a value, or with a word like yes, does not work. Checked offline in Windows PowerShell 5.1 with module 16.0.27709.12000:

powershell
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
$p = (Get-Command Get-SPOSite).Parameters['IncludePersonalSite']
"Type: " + $p.ParameterType.Name + " of " + $p.ParameterType.GenericTypeArguments[0].Name
try { Get-SPOSite -IncludePersonalSite yes -ErrorAction Stop } catch { $_.Exception.Message }
try { Get-SPOSite -IncludePersonalSite $true -Limit All -ErrorAction Stop } catch { $_.Exception.Message }

Output

Type: Nullable`1 of Boolean
Cannot convert 'System.String' to the type 'System.Nullable`1[System.Boolean]' required by parameter 'IncludePersonalSite'.
No connection available. Use Connect-SPOService before running this CmdLet.

The first call fails while binding the parameter; the second binds correctly and only fails because there is no Connect-SPOService session (No connection available).

CommandReturns
Get-SPOSite -Limit Allall SharePoint sites, no OneDrive
Get-SPOSite -IncludePersonalSite $true -Limit AllSharePoint and OneDrive sites
... -Filter "Url -like '-my.sharepoint.com/personal/'"only OneDrive sites (documented example)
Get-SPOSite -Identity https://contoso-my.sharepoint.com/personal/anna_contoso_comone OneDrive, no switch needed
Get-SPOSite -Template GROUP#0 -IncludePersonalSite:$falsegroup sites only; the colon form also passes the Boolean (reference example)

Pitfalls

  • Default limit. Without -Limit All you get at most 200 sites in total; see Get-SPOSite -Limit All.
  • Permissions on the data. Listing OneDrive sites needs the SharePoint Administrator role; it does not give access to the files in them.
  • Properties. With -Limit, some properties are not populated; storage values for many sites are better read as shown on storage usage.
  • Deleted users. Retention of orphaned OneDrive sites is controlled by OrphanedPersonalSitesRetentionPeriod.

FAQ

How do I list only OneDrive sites?

Use the filter from Microsoft's article on listing OneDrive URLs: Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'". It returns the personal sites and leaves out the SharePoint sites.

Why does -IncludePersonalSite yes fail?

The parameter is a nullable Boolean, not a switch, so it needs a Boolean value such as $true. A word like yes cannot be converted, as shown on this page.

Can I see a OneDrive site of a deleted user?

While the OneDrive is retained after the account is deleted, it is still a site and appears with -IncludePersonalSite $true. How long it is kept is set by OrphanedPersonalSitesRetentionPeriod.

Sources