I have written a script to create folders in SPO, this script creates a group, then a folder and assigns the group permission to the folder. The only issue is that the folder is created by the user running the script, so the folder has permissions for the creating user & the group.
After creating the folder and assigning permissions, I want to go back and remove any users that have permission on that folder (excluding the group i created).
I've seen quite a few guides on how to do this but I'm getting stuck when debugging as things aren't initializing correctly.
Take for instance this guide.
It starts by getting the site context and using the web property to handle all of the permissions. Up to this line my code debugs fine:
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Site) $ctx.Credentials = $creds
The next step is to run the following:
$Web = $Ctx.Web #Get the Folder $Folder = $Web.GetFolderByServerRelativeUrl($folderurl) $Ctx.Load($Folder) $Ctx.ExecuteQuery()
However when inspecting values in debug, $Web is completely empty and never gets assigned. Here is my context object initialised:
and here is the
$Web variable (after attempting to set it):
As you can see this variable has not been set even though it exists in the context variable. How can I fix this issue? I've not seen much about it and I'm at a loss on how I can actually connect to sharepoint and remove the permissions now!