As a bunch of us are starting to convert their environments over to Online SharePoint and Teams we are having to adjust how we do things. Now that teams uses the SharePoint Online as its back end file structure.
Problem: Need to find a way to add files to a teams site from an automated script.
Doing some research found there was a simple way to do this. The simplest easy way to add files to a Teams site is just to send a email to the teams email address. Odds are you are already emailing the report or task results to yourself or a team, why not just add the teams site Address. How do you find the email address? Well inside your teams site and the channel you want to send it to. Click on the three dots. It will look something like below.

Click on the Get Email address button and you will now have the email. This works if you are just sending email results to Teams. But what if you have an attachment. Well that also works. But its listed as an email attachment.
What if I just want to send a file on its own with no email? This is where things got fun. As teams has no real API that you can really use for stuff like this. (I may be wrong, as I could not find one.) Only way I could figure to do this was to add the files direct to the back end SharePoint site.
This requires you to install the PowerShell Module: SharePointPnPPowerShellOnline. This will give you the functions of where you can connect to SharePoint site and upload files directly to where you want them to go.
If you are trying to drop a single file into a teams file share you can run the command below:
$SharepointURL = "https://youteamssite.sharepoint.com/sites/TeamsName" $OutPath = "C:\Temp\ToSharepoint\Test.txt" Connect to Sharepoint Connect-PnPOnline $SharepointURL -Credentials $(Get-Credential) Send File to Teams Sharepoint site Add-PnPFile -Folder "Shared Documents/Reports/FolderName" -Path $OutPath
If you want to add contents of a folder you can just add a loop and copy all files from that folder to the teams site.
$SharepointURL = "https://youteamssite.sharepoint.com/sites/TeamsName"
$OutPath = "C:\Temp\ToSharepoint"
Connect to Sharepoint
Connect-PnPOnline $SharepointURL -Credentials $(Get-Credential)
Send Files to Teams Sharepoint site
$Files = Get-ChildItem "$OutPath"
foreach($File in $Files){
Add-PnPFile -Folder "Shared Documents/Reports/FolderName" -Path $File.FullName
}
Add one of the two above to any of your reporting scripts and now you will have reports directly dumped into your Teams Site “Files” directory.

