使用Powershell将文件夹结构到teamsite

时间:2016-06-28 13:02:47

标签: powershell directory sharepoint-online teamsite

之前我曾问过这个问题,但有一点错误。再说一次:

我尝试使用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

我希望有人可以告诉我什么是错的。

提前致谢和许多问候

安迪

1 个答案:

答案 0 :(得分: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()

来自:Copy folder structure from one list to another in a different site collection

您还可以查看Technet Gallery中的其他脚本:copy folder