Export and backup files in Teams channel or space?

EnterpriseArchitect 6,041 Reputation points
2023-02-22T02:30:45.0933333+00:00

Hi All,

Is there any script or method to export files from the Teams channel or space before I delete it?

Thank you in advance.

Microsoft Teams | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
Microsoft Teams | Microsoft Teams for business | Other
0 comments No comments
{count} votes

Accepted answer
  1. Xyza Xue_MSFT 30,176 Reputation points Microsoft External Staff
    2023-02-22T09:25:43.32+00:00

    Hi @Enterprise Architect ,

    The files in Teams channel are stored in the automatically created sharepoint site, and can be exported to the specified path using Pnp powershell.

    If you have not used PnP powershell, please install PnP.PowerShell Module first :

    Install-Module PnP.PowerShell -Scope CurrentUser
    

    Pnp powershell code(You just need to replace $SiteURL and $DestinationFolder):

    #Config Variables
    $SiteURL = "https://yourdomain.sharepoint.com/sites/yoursite"
    $FolderSiteRelativeUrl = "/Shared Documents/General" 
    $DestinationFolder ="C:\SP"
    
    #Get Credentials to connect
    $Cred = Get-Credential
      
    Try {
        #Connect to PnP Online
        Connect-PnPOnline -Url $SiteURL -Credentials $Cred
      
        #Get All Files from the Folder
        $FolderItems = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderSiteRelativeUrl -ItemType File -Recursive
         
        Write-host "Total Number of Files in the Folder:" $FolderItems.Count
        $Files = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderSiteRelativeUrl -ItemType File  
        foreach($File in $Files) {   
    	Write-host -f magenta "Downloading file:" $File.Name      
        	Get-PnPFile -Url $File.ServerRelativeUrl -Path $DestinationFolder -FileName $File.Name -AsFile  
    	Write-host "*** Download Completed  ***"    -foregroundcolor Green   
        } 
    }
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
    
    

    The running result is as below:

    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.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

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.