0

I asked this question once before, but there was a little mistake. So again:

I'm trying to integrate a folder structure of a folder, which is located on my PC to a Document Library of a Team Site on SPO using Powershell. After I created the team site I use the following script:

$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 $_
}

I am able to display the folders with "Write-Host" and I also have the rights for the folder, but I can not upload it. There comes following error message for each folder and subfolder:

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

I hope someone can tell me what's wrong.

Thanks in advance and many greetings

Andy

andyohn
  • 25
  • 4
  • 1
    Is `Test-Path $_.FullName` working? – hdev Jun 28 '16 at 14:54
  • No it's not working.. Test-Path : The argument can not be bound to the parameter " Path " since it is NULL . In line: 1 char : 11 + Test-Path $_.FullName + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand – andyohn Jun 29 '16 at 10:16
  • if it's just a folder, is there any reason to add .ContentStream? – grisha Jul 11 '16 at 06:02

1 Answers1

0

How to add a folder to SharePoint Online (omitting the .ContentStream parameter):

$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()

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

You can check also other scripts from Technet Gallery: copy folder

grisha
  • 389
  • 1
  • 8
  • 22