Forum Discussion
Tim Gade
May 17, 2017Former Employee
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 expectin...
May 17, 2017
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
Cheers
Tim Gade
May 17, 2017Former Employee
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