Forum Discussion
script to copy files from on premise file server to SP ONLINE
0I have a script that I found in many forms online that I re-tooled to work in my environment.
The purpose of the script is to copy files from local File Server to a Library on my SharePoint Online.
I have it working to the site I want it to go to as long as the site's "Members Group" has Write Access to the sub directory. in this scenario, I need to limit access to this library and don't want the Sites "Members Group" to have access.
when I remove the "Members Group" and add explicit permissions for the Licensed O365 User that executes the upload, I get these errors:
You cannot call a method on a null-valued expression.
At C:\TESTMove_file.ps1:70 char:5
+ $FileUploaded = $FolderToUpload.Files.Add($FileCreationInfo)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNullCannot find an overload for "Load" and the argument count: "1".
At C:\TESTMove_file.ps1:73 char:2
+ $Context.Load($FileUploaded)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBestException calling "ExecuteQuery" with "0" argument(s): "The remote server returned an
error: (401) Unauthorized."
At C:\TESTMove_file.ps1:74 char:5
+ $Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebExceptionI haven't been able to find a reason this wouldn't work? Please advise.
thanks
4 Replies
- Doug AllenIron Contributor
Did you give these named users Contribute or Edit permissions? The members group has Edit by default and I've seen strange behavior if you drop to Contribute.
- DH_SavageCopper Contributor
yes the User that I use to Connect to Sharepoint is in the "Owners" group for that document library.
I have even explicitly granted it Full control over the library.
- Doug AllenIron Contributor
Besides the script, was there a reason why you weren't using the free SharePoint migration tool to migrate the files instead of the script?
https://docs.microsoft.com/en-us/sharepointmigration/fileshare-to-odsp-migration-guide