Jump to content

Teams - Sharepoint change folder permissions


Recommended Posts

Posted

Hi there

 

Im trying to change the permissions of the Shared Documents folder in teams using powershell, however I seem to have run in to a wall. I can change any user created folders fine but for the shared documents or general folder I get an error that folder must be updated in teams. Does anyone know a different method I can do this? I have 100’s to update

 

It’s changing permission of the teams members to remove edit access.

 

Thanks

Posted
I use Set-PnpFolderPermission command to update permissions on folders within a SharePoint document library without issue.

 

Hi there, I can update user created folders but not the Teams “General” folder as I get the error “Set-PnPFolderPermisson : to update this folder , go to the Chanel in Microsoft Teams

 

I get the same error if I try command Set-PnPListItemPermission

 

Thanks

Posted

Hi again

 

Im missing something as its still not working for me, here is the code i'm using.

 

Thanks

 

 

 #Import data from CSV
$Import = Import-csv C:\test\test.csv

#Select the required teams
$Import = $Workingdata | Out-GridView -PassThru

# Find the sharepoint url of the team
$site = Get-UnifiedGroup -Identity $workingdata.GroupId
$site | Format-List DisplayName,EmailAddress,SharePointSiteUrl

# Create group name
$Members = $Workingdata.DisplayName+" Members"

#Set site from url
$SiteURL = $site.SharePointSiteUrl

#Folder name
$ListName = "Documents"

$FolderServerRelativeURL = '/sites/TrainingTeam8/Shared Documents/'

#Roles to assign
$Role = "Read"


Connect-PnPOnline -Url $SiteURL -Interactive

#Collect folder names
Try {

$AllFolders = Get-PnPFolderItem -FolderSiteRelativeUrl "/Shared Documents"  -ItemType Folder -ErrorAction Stop
}

Catch {
Write-host "Failed to list the folders" -ForegroundColor Red

Exit

}


Foreach ($Folder in $AllFolders) {

$RelativeURL=$FolderServerRelativeURL+$Folder.name
Write-host $RelativeURL

$folderitem = Get-PnPFolder -Url $RelativeURL

#Set-PnPListItemPermission -List $ListName -Identity $folderitem.ListItemAllFields -ClearExisting -Group $Members
#Set-PnPListItemPermission -List $ListName -Identity $folderitem.ListItemAllFields -AddRole $role -Group $Members

Set-PnPFolderPermission -List $ListName -Identity $RelativeURL -ClearExisting -Group $useraccount
Set-PnPFolderPermission -List $ListName -Identity $RelativeURL -AddRole $role -Group $useraccount


}



Posted

I've done:

 

$targetFolderBind = Resolve-PnPFolder -SiteRelativePath "$sharepoint_folder/$folder_name"

 

Then done:

 

Set-PnpFolderPermission -List $sharepoint_folder -Identity $targetFolderBind -User "XX@XX" -AddRole "Read"

Posted
Hi again

 

Im missing something as its still not working for me, here is the code i'm using.

 

Thanks

 

 

 #Import data from CSV
$Import = Import-csv C:\test\test.csv

#Select the required teams
$Import = $Workingdata | Out-GridView -PassThru

# Find the sharepoint url of the team
$site = Get-UnifiedGroup -Identity $workingdata.GroupId
$site | Format-List DisplayName,EmailAddress,SharePointSiteUrl

# Create group name
$Members = $Workingdata.DisplayName+" Members"

#Set site from url
$SiteURL = $site.SharePointSiteUrl

#Folder name
$ListName = "Documents"

$FolderServerRelativeURL = '/sites/TrainingTeam8/Shared Documents/'

#Roles to assign
$Role = "Read"


Connect-PnPOnline -Url $SiteURL -Interactive

#Collect folder names
Try {

$AllFolders = Get-PnPFolderItem -FolderSiteRelativeUrl "/Shared Documents"  -ItemType Folder -ErrorAction Stop
}

Catch {
Write-host "Failed to list the folders" -ForegroundColor Red

Exit

}


Foreach ($Folder in $AllFolders) {

$RelativeURL=$FolderServerRelativeURL+$Folder.name
Write-host $RelativeURL

$folderitem = Get-PnPFolder -Url $RelativeURL

#Set-PnPListItemPermission -List $ListName -Identity $folderitem.ListItemAllFields -ClearExisting -Group $Members
#Set-PnPListItemPermission -List $ListName -Identity $folderitem.ListItemAllFields -AddRole $role -Group $Members

Set-PnPFolderPermission -List $ListName -Identity $RelativeURL -ClearExisting -Group $useraccount
Set-PnPFolderPermission -List $ListName -Identity $RelativeURL -AddRole $role -Group $useraccount


}



 

The first line should be $Workingdata = Import-csv C:\test\test.csv instead of $Import = Import-csv C:\test\test.csv

 

On line 4, $Import = $Workingdata | Out-GridView -PassThru is not necessary and can be removed.

 

On line 8, $site | Format-List DisplayName,EmailAddress,SharePointSiteUrl is not necessary and can be removed.

 

On line 11, $Members = $Workingdata.DisplayName+" Members" is not necessary and can be removed.

 

On line 16, $FolderServerRelativeURL = '/sites/TrainingTeam8/Shared Documents/' should be changed to use the URL obtained from the SharePoint site.

 

On line 20, Connect-PnPOnline -Url $SiteURL -Interactive should be used to connect to the SharePoint site before trying to access the folders.

 

On lines 27 and 28, -List $ListName should be removed and -Identity $RelativeURL should be changed to -Identity $folderitem.

 

On lines 29 and 30, -Group $useraccount should be changed to -Group $Members.

Posted
I've done:

 

$targetFolderBind = Resolve-PnPFolder -SiteRelativePath "$sharepoint_folder/$folder_name"

 

Then done:

 

Set-PnpFolderPermission -List $sharepoint_folder -Identity $targetFolderBind -User "XX@XX" -AddRole "Read"

 

I've tried again using the same lines as you have.

$targetFolderBind = Resolve-PnPFolder -SiteRelativePath "Shared Documents/General"

Set-PnpFolderPermission -List "Shared Documents" -Identity $targetFolderBind -Group $Members -AddRole "Read"

And still get to update this folder go the the channel in Microsoft Teams

 

Thanks

Posted

OK, so does the same code update another folder in "Shared Documents" not General? ie. "Shared Documents/Test"

 

And if you create a folder in "General" can you update that using the same code, i.e "Shared Documents/General/Test"?

 

General might be protected or work differently since its a special folder.

Posted
OK, so does the same code update another folder in "Shared Documents" not General? ie. "Shared Documents/Test"

 

And if you create a folder in "General" can you update that using the same code, i.e "Shared Documents/General/Test"?

 

General might be protected or work differently since its a special folder.

 

Yes i've just used the code below to update a folder called Test

 

Thanks

 

$targetFolderBind = Resolve-PnPFolder -SiteRelativePath "Shared Documents/Test"

Set-PnpFolderPermission -List "Shared Documents" -Identity $targetFolderBind -Group $Members -AddRole "Read"

Posted
The first line should be $Workingdata = Import-csv C:\test\test.csv instead of $Import = Import-csv C:\test\test.csv

 

On line 4, $Import = $Workingdata | Out-GridView -PassThru is not necessary and can be removed.

 

On line 8, $site | Format-List DisplayName,EmailAddress,SharePointSiteUrl is not necessary and can be removed.

 

On line 11, $Members = $Workingdata.DisplayName+" Members" is not necessary and can be removed.

 

On line 16, $FolderServerRelativeURL = '/sites/TrainingTeam8/Shared Documents/' should be changed to use the URL obtained from the SharePoint site.

 

On line 20, Connect-PnPOnline -Url $SiteURL -Interactive should be used to connect to the SharePoint site before trying to access the folders.

 

On lines 27 and 28, -List $ListName should be removed and -Identity $RelativeURL should be changed to -Identity $folderitem.

 

On lines 29 and 30, -Group $useraccount should be changed to -Group $Members.

 

 

Thanks for the comment.

 

Line 1 is like that for a reason,

Line 4 is like that so i can select the team(s) for testing

Line 8 is so that i can see the url of the team

Line 11 is create the name of the members group

Line 16 will be pulled once i can get the test working.

Line 20 is there as i'm going to put a foreach loop above it i can get it working.

Line 27 and 28 not sure what you mean if i remove -List then the command will not run

Line 29 and 30 i agree it should now say $Members

 

Thanks

Posted
OK, so does the same code update another folder in "Shared Documents" not General? ie. "Shared Documents/Test"

 

And if you create a folder in "General" can you update that using the same code, i.e "Shared Documents/General/Test"?

 

General might be protected or work differently since its a special folder.

 

Hi there

 

Yes i can change permissions on Shared Documents/Test and also Shared Documents/General/Test

 

Thanks

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...