通过 BITS 上传到 OneDrive

Upload to OneDrive via BITS

我正在尝试使用 BITS 将文件提交到 OneDrive。 我在这里找到了一篇关于此的文章:https://msdn.microsoft.com/en-us/library/dn858877.aspx;但我希望 PowerShell 的本机 Start-BitsTransfer 方法可以节省我一些精力。但是那篇文章暗示 OneDrive 支持 BITS 上传;所以事情很有希望。

$source = '\myFileServer\Backups\SqlServerDbBackup.bak' #3.2GB file
$destination = 'https://myCompany.sharepoint.com/personal/my_account/Documents/SqlServerDbBackup.bak'
$cred = get-credential #here I enter the same credentials I use to access the site
Start-BitsTransfer -Source $source -Destination $destination -TransferType Upload -Credential $cred

当我运行上面的代码时,进度条短暂弹出,然后出现错误。完整输出(包括凭据提示)如下:

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Start-BitsTransfer : HTTP status 501: The server does not support the functionality required to fulfill the request.
At line:8 char:1
+ Start-BitsTransfer -Source $source -Destination $destination -TransferType Uploa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Start-BitsTransfer], Exception
    + FullyQualifiedErrorId : StartBitsTransferCOMException,Microsoft.BackgroundIntelligentTransfer.Management.NewBitsTransferCommand

之前有没有人尝试过/有任何想法是否可以使用 start-bitstransfer 执行上传到 OneDrive?

您似乎正在尝试上传到 OneDrive for Business。您找到的 MSDN 文章适用于个人 OneDrive; OneDrive for Business 不支持 BITS。虽然您不能使用 Start-BitsTransfer,但您可以找到有关新上传 API 的 here 的信息,它适用于个人和企业 OneDrives。