0

这个问题我以前问过一次,但是有一点小错误。再说一遍:

我正在尝试使用 Powershell 将位于我的 PC 上的文件夹的文件夹结构集成到 SPO 上的团队站点的文档库。创建团队网站后,我使用以下脚本:

$Folder = "D:\Skripte\04_Manuelle_Ausfuehrung\Office 365\CreateSite\Teamseiten"
$DocLibName = "Dokumente"

#Retrieve list
$List = $ctx.Web.Lists.GetByTitle($DocLibName)
$ctx.Load($List)
$ctx.ExecuteQuery()


#Upload file
Get-ChildItem -Recurse $Folder | 
Foreach-Object {
$FileStream = New-Object IO.FileStream($_.FullName,[System.IO.FileMode]::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $_
$Upload = $List.RootFolder.Files.Add($FileCreationInfo)
$ctx.Load($Upload)
$ctx.ExecuteQuery()
Write-Host $_
}

我可以使用“Write-Host”显示文件夹,并且我也拥有该文件夹的权限,但我无法上传它。每个文件夹和子文件夹都有以下错误消息:

New-Object: Exception calling ".ctor" with 2 argument (s): "Access to the path" D:\scripts\04_Manuelle_Ausfuehrung\Office 365\Createsite\Team Sites\01_Bekanntmachung and guidelines "
was denied."
In D:\scripts\04_Manuelle_Ausfuehrung\Office 365\Createsite\SPOCreateSite.ps1: 84 mark: 15
+ $FileStream = New-Object IO.FileStream ($_.FullName, [System.IO.FileMode] :: Open)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
    + Category Info: InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId: ConstructorInvokedThrowException, Microsoft.PowerShell.Commands.NewObjectCommand

Exception calling "executeQuery" with 0 Argument (s): "parameters.Content, parameters.ContentStream
Parameter name: The specified value is not supported parameters.ContentStream parameters for parameters.Content ".
In D:\scripts\04_Manuelle_Ausfuehrung\Office 365\Createsite\SPOCreateSite.ps1: 91 mark: 1
+ $Ctx.ExecuteQuery ()
+ ~~~~~~~~~~~~~~~~~~~
    + Category Info: NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId: ServerException

我希望有人能告诉我出了什么问题。

预先感谢和许多问候

安迪

4

1 回答 1

0

如何将文件夹添加到 SharePoint Online(省略 .ContentStream 参数):

$lici =New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$lici.UnderlyingObjectType=[Microsoft.SharePoint.Client.FileSystemObjectType]::Folder
$lici.LeafName=$urel2
$newFolder=$ll2.AddItem($lici)#$ll2.RootFolder.ServerRelativeUrl, [Microsoft.SharePoint.Client.FileSystemObjectType]::Folder)
$ctx2.Load($newFolder)
$newFolder.Update()
$ctx2.ExecuteQuery()
$newFolder["Title"]="Your title"
$newFolder.Update()
$ctx2.ExecuteQuery()

来自:将文件夹结构从一个列表复制到另一个网站集中的另一个列表

您还可以查看 Technet Gallery 中的其他脚本:复制文件夹

于 2016-07-11T06:08:38.000 回答