OneDrive for Business - Upload document using PowerShell / CSOM

Microsoft

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

2 Replies

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