How to List All Files in SharePoint and Teams Channel Sites?

Claire Mather 20 Reputation points
2024-08-08T16:39:52.46+00:00

I am trying to create an script to list all documents in SharePoint sites and their corresponding Teams channel sites.

 

I have tried using the Graph API to list all sites; however, it only gives me back the Teams channel sites and sites that don't have associated Teams channels. I have also tried using the SharePoint Online PowerShell module. The Get-SPOSite cmdlet works to list all sites, but there is no cmdlet to list the files in a site and the site information returned by the Get-SPOSite does not contain the ObjectGuid which is needed for the Graph API request that lists the documents.

 

Is there a way to configure the Graph API request to list all sites? Are there any other ways to list the SharePoint sites and their documents other than the two methods I have tried?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,282 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,431 questions
0 comments No comments
{count} votes

Accepted answer
  1. Emily Du-MSFT 51,271 Reputation points Microsoft External Staff
    2024-08-09T09:49:50.1466667+00:00

    Per my test, there is no one graph can bother list all Teams connected sites and all files in the site.

    You should do this through PowerShell and graph.

    1.List all Teams connected sites through PowerShell.

    #Connect to SharePoint Service
    Connect-SPOService -Url "https://Crescent-admin.sharepoint.com"
    #Get All Microsoft Teams Connected Sites
    Get-SPOSite -Limit All | Where {$_.IsTeamsConnected -eq $True}
    #Get all Teams Channel Connected
    Get-SPOSite -Limit All | where {$_.IsTeamsChannelConnected -eq $True}
    

    2.List all files in a site through graph.1


    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Vasil Michev 115.5K Reputation points MVP
    2024-08-08T17:19:00.13+00:00

    There is, but only when you use application permissions: https://learn.microsoft.com/en-us/graph/api/site-list?view=graph-rest-1.0&tabs=http

    This query will return all sites, including those associated with Teams, as well as personal ODFB sites. You can exclude the latter with a filter if needed. Once you have the list of sites, you can iterate over each of them and list files. Be mindful of throttling though, especially for large sites.

    If you need a sample script that uses this method, check this one I wrote a while back: https://www.michev.info/blog/post/6154/report-on-externally-shared-files-via-the-graph-api

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.