Forum Discussion
OneDrive for Business - Upload document using PowerShell / CSOM
I am trying to upload a file (actually copy a file from a SP site) to the default Documents list in OneDrive for Business but the Copy-PnPFile -SourceUrl $source -TargetUrl $target cmdlet is expecting a relative path versus an absolute path to https://tenant-my.sharepoint.com …
Unfortunately I have not been able to find any PowerShell examples that can upload a file to OneDrive. Is it even possible?
Tim
- This is an old Script, but it should work: https://blogs.technet.microsoft.com/fromthefield/2014/02/19/office-365-powershell-script-to-upload-files-to-a-document-library-using-csom/
Cheers- Tim GadeMicrosoft
Thank you. Vesa also pointed me to the fact that I could connect to the OD4B site directly using the connect-pnponline PnP cmdlet and then use the Add-PnPFile cmdlet to upload the file.
connect-pnponline -Url $OneDriveURL –Credentials (Get-Credential)
Add-PnPFile -Path $Source -Folder "Documents" -Values @{Modified="5/1/2017"}https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/AddPnPFile.md