Yes! Store the PowerShell output directly to SharePoint Online using modern authentication. The two reliable approaches are PnP.PowerShell (simplest) or Microsoft Graph (best for automation/service principals). With PnP.PowerShell, export your data to an .xlsx on disk as you already do, then connect and upload:
Install once: Install-Module PnP.PowerShell $siteUrl = "https://contoso.sharepoint.com/sites/Finance"
$library = "Shared Documents/Reports" # Library/Folder path
$local = "C:\Reports\query-result.xlsx"
Connect-PnPOnline -Url $siteUrl -Interactive # MFA-supported sign-in
Add-PnPFile -Path $local -Folder $library -OverwriteIfAlreadyExists
If you need unattended runs, use Graph with an app registration that has Files.ReadWrite.All or Sites.Selected, grant site access, and then upload to the library’s drive:
Install once: Install-Module Microsoft.Graph Connect-MgGraph -Scopes "Files.ReadWrite.All"
$site = Get-MgSite -Filter "displayName eq 'Finance'"
$drive = Get-MgSiteDrive -SiteId $site.Id | Where-Object {$_.Name -eq "Documents"}
$bytes = [System.IO.File]::ReadAllBytes("C:\Reports\query-result.xlsx")
New-MgDriveItemContent -DriveId $drive.Id -DriveItemId "root:/Reports/query-result.xlsx:/content" -BodyParameter $bytes -ContentType "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Avoid legacy WebDAV mapping or basic auth; they’re brittle and deprecated. Ensure your account or app has at least Contribute permissions on the target library and confirm library settings such as required checkout or mandatory metadata, which can block uploads. If you prefer CSOM, you can use Microsoft.SharePointOnline.CSOM with SharePointOnlineCredentials, but favor PnP or Graph for MFA and app-based auth. If you need me to adapt your existing script, share how you generate the Excel, your tenant URL, target library/folder, and whether this runs interactively or on a scheduled task.
I hope you've found something useful here. If it helps you get more insight into the issue, it's appreciated to accept the answer. Should you have more questions, feel free to leave a message. Have a nice day!
Harry