I wrote a powershell script to upload a file to sharepoint online.
The script works fine in PowerShell ISE, but throws an error when used in a powershell studio form. Can some one help me figure this out?
$FileStream = New-Object IO.FileStream($SourceFile.FullName, [System.IO.FileMode]::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $File
$Upload = $List.RootFolder.Files.Add($FileCreationInfo)
$Context.Load($Upload)
$Context.ExecuteQuery()
throws error:
ERROR: Exception calling "Add" with "1" argument(s): "The 'parameters.Url' argument is invalid."
Test-OneDrive.psf (93, 5): ERROR: At Line: 93 char: 5
ERROR: + ... $Upload = $targetFolder.Files.Add($FileCreationInfo);
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
ERROR: + FullyQualifiedErrorId : ArgumentException
ERROR:
ERROR: Cannot find an overload for "Load" and the argument count: "1".
Test-OneDrive.psf (97, 4): ERROR: At Line: 97 char: 4
ERROR: + $Context.Load($Upload)
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : NotSpecified: (:) [], MethodException
ERROR: + FullyQualifiedErrorId : MethodCountCouldNotFindBest
ERROR:
Upload a file to Sharepoint
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: Upload a file to Sharepoint
Probably works in the ISE because $File is contaminated from
something else but not initialized in the script.
something else but not initialized in the script.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.