I have 200 files I need to upload regularly to sharepoint 365, users sync that folder with onedrive. Now, some guy has come along and added a bunch of "properties" for my files, such as "Category" and "Target Audience" to sharepoint. Now, I am a lazy bugger, so I have created a ps1 file with a bunch of functions to create, delete folders and create, delete, upload files and have an automated workflow to upload the files to sharepoint automagically. I now need to programmatically set these "properties" on the files.
When I use the browser to look at my files, I can set values for these properties via a drop-down or radio buttons.
I found these two sources:
These make me believe that this "should work":
//$file is Microsoft.SharePoint.Client.File PS > $file.Properties.FieldValues["Category"]="Training" PS > $file.Update()
However, when I do that, nothing happens. If I do:
//ctx is Microsoft.SharePoint.Client.ClientContext PS > $file.Properties.FieldValues["Category"]="Training" PS > $ctx.Load($file.Properties) PS > $ctx.ExecuteQuery()
I get an error:
Exception calling "ExecuteQuery" with "0" argument(s): "Field or property "Category" does not exist." At line:1 char:1 + $ctx.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) , MethodInvocationException + FullyQualifiedErrorId : ServerException
Now, I know there is a combination of the above that works, because I managed it twice, by mixing the above, but I am unable to get a consistent behavior.
Another thing, I tried to find the properties in the list in question:
//$List is Microsoft.SharePoint.Client.List $List.Fields | select InternalName
I do not get Category or target audience
Now, i can manually set the fields on the files, but that is not an option for me ... any thoughts, what am I doing wrong ? If there is a way I can help you help me, please do advise ;-).