Using Powershell and CSOM, on Sharepoint Online, I have successfully upoaded 300K pdf files w/metadata into folders in document libraries.

Today, though, the same code is failing to Add files...

Snippets of code follow:

#Get File Collection for folder
$Files = $folder.Files

    # Setup FileStream and FileInfo
    $FileStream = New-Object IO.FileStream($SrcFilePath,[System.IO.FileMode]::Open)
    $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
    $FileCreationInfo.Overwrite = $true
    $FileCreationInfo.ContentStream = $FileStream
    $FileCreationInfo.URL = $folderUrl + '/' + $_.SedaID

    # Upload FIle
    $Upload = $Files.Add($FileCreationInfo)

    # Update Metadata
    Set-SPOListItem -List $listTitle -Identity $($Upload.ListItemAllFields.Id) `
        -ContentType "SEDA Document" -Values $Metadata
    $ErrorMessage = $_.Exception.Message
    $ItemFailed = $true
    $FailCount += 1

    “$Time : Error Uploading {0}:`t   {1}" -f $_.SedaID, $ErrorMessage | out-file $ErrorFile -append


$Filestream appears legit:

enter image description here

$FileCreationInfo appears legit:

enter image description here

But folder.Files.Add(FileCreationInfo) now Errors like this:

enter image description here

Any idea what I am doing wrong this time?

  • does the 2016 folder exist? Doing the same thing atm, and if the folder doesn't exist, you have to create it first, then upload the file. Commented Nov 4, 2016 at 16:00
  • Thx @Eric, yes this folder exists, and if it didn't, my code would create it. I didn't include this part of the code in my snippet... Commented Nov 4, 2016 at 16:37
  • Can you try doing this against another tenant?
    – James Love
    Commented Nov 6, 2016 at 21:51
  • Thx @James, I don't have another tennant, but I do have another site collection, which doesn't error at all when running the same code... I have no idea what the issue is, and the error message is useless... Commented Nov 7, 2016 at 19:46

1 Answer 1


After confirming that all of the code was correct, and experiencing multiple, unrelated errors (invalid cast errors, out-of-memory, etc.), I decided to uninstall/reinstall WMF 5 (w/powershell 5) and reinstall the latest Sharepoint Online Client assemblies, and my application worked flawlessly! I'm not sure what caused the corruption(s) in the platform, but one area I know could be improved, and that's the error messaging across the entire Microsoft 'echosystem'... There was no clue whatsoever!

  • And after uploading 12,000 items yesterday, today it is failing the same way it did before the re-install! Any further suggestions from the expertas out there? How about Microsoft? Commented Nov 9, 2016 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.