Get-MgSite -search "*"

Jesus Chao 141 Reputation points
2023-02-07T21:27:36.44+00:00

At some point in the last month, we have lost the ability to use the following command:

get-mgsite -search "*"

This command would result in a listing of all the Sharepoint Online sites in my tenant. Now it returns nothing. In fact, most terms that I enter in the -search query field return nothing.

get-mgsitelist requires the siteid as a parameter and I am not sure how I can get the site ID if I cannot search for the site by name. For example:

$siteid = (Get-MgSite -Search "*" | where {$_.name -eq "<SiteName>"}).id

$listid = (Get-MgSiteList -SiteId $siteid| where {$_.name -eq "<listname>"}).id

How do you list all the sites in the tenant now?

I work around this issue by performing the following:

Get-MgSite -siteid "<domain>.sharepoint.com**:**/sites/<sitename>"

Thanks,

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,714 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-02-08T13:01:59.1766667+00:00

    Hi @Jesus Chao ,

    Thanks for reaching out!

    You can use below the API to get the site by searching the sitename,

    https://graph.microsoft.com/v1.0/sites?search="NameofSite"

    In PowerShell use the below command,

    Get-MgSite -Search "NameofSite"

    To get server-relative URL for a site resource, you can construct a request as GET /sites/{hostname}:/{server-relative-path}, refer access-a-site-by-server-relative-url

    Listing all the sites is supported only in application permissions, reference link: List Sites.

    Hope this helps.

    If the reply is helpful, please click Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment". 


  2. Zehui Yao_MSFT 5,831 Reputation points
    2023-02-14T02:49:34.9266667+00:00

    Hi @Jesus Chao , another workaround I can offer is to use SharePoint Online Management Shell, I don't know if it meets your needs.

    User's image

    Since I found the same issue while testing locally, Get-MgSite didn't return anything, so I recommend opening a support ticket to communicate with the product group to confirm if there are any updates. Thank you very much for your understanding.

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.