Hello everyone,
I'm trying to create a PS script that reads the set permissions of a folder from SharePoint and creates a copy of it with the same rights.
In MS Entra Admin Center, I've created a new app and granted it numerous permissions for testing purposes.
My PS7 script looks like this:
$clientId = "[...]"
$clientSecret = "[...]"#Value, not the ID
$tenantId = "[...]"
$siteUrl = "[...].sharepoint.com/sites/ExterneKundendaten"
$libraryName = "Dokumente"
$folderPath = "_Unsortiert"
try {
$connection = Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret Write-Host "Connection successfully established"
}
catch { Write-Host "Connection error: $_"}
I'm getting the following error message:
Connection error: The remote server returned an error: (401) Unauthorized.
For testing, I've also tried the following connection setup:
$clientSecretSecure = ConvertTo-SecureString $clientSecret -AsPlainText -Force
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecretSecure
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret -Tenant $tenantId
$clientSecretSecure = ConvertTo-SecureString $clientSecret -AsPlainText -Force
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecretSecure -Tenant $tenantId
Unfortunately, all without success.
This is roughly how the later process should be, but it's already stuck at point 1
1. Establish connection to SharePoint Online
2. Define library name and folder path
$libraryName = "Dokumente" # Name of the document library
$folderPath = "_Unsortiert" # Path to the folder
3. Get the list item for the folder
$folderItem = Get-PnPListItem -List $libraryName -FolderServerRelativeUrl "/sites/ExterneKundendaten/$libraryName/$folderPath"
4. Get the role assignments for the folder
$roleAssignments = Get-PnPRoleAssignment -List $libraryName -Identity $folderItem.Id
5. Display permissions
$roleAssignments | Format-Table Principal, RoleDefinitionBindings
6. Disconnect
Disconnect-PnPOnline
PSVersion 7.4.6
PnP.PowerShell 2.12.0
Does anyone have an approach on how I can proceed and/or can someone recommend a good (and current!!) tutorial?