Hi @Shandy T ,
Welcome to Q&A Forum!
According to my research, there is no similar -FileValues parameter in PnPListItems in PowerShell commands.
Get-PnPListItem
[-List] <ListPipeBind>
[-FolderServerRelativeUrl <String>]
[-Fields <String[]>]
[-PageSize <Int32>]
[-ScriptBlock <ScriptBlock>]
[-Connection <PnPConnection>]
[<CommonParameters>]
Set-PnPListItem
[-List] <ListPipeBind>
-Identity <ListItemPipeBind>
[-ContentType <ContentTypePipeBind>]
[-Values <Hashtable>]
[-UpdateType <UpdateType>]
[-Label <String>]
[-ClearLabel]
[-Connection <PnPConnection>]
Thanks,
Echo Du
===========================
Updated Answer =========================
Hi @Shandy T ,
According to my understanding, we cannot restrict access to all .xlsx files within each of the folder through “AccessPolicy” and “Restricted”.
SharePoint access control policies:
Microsoft recommends you protect content in SharePoint sites with enterprise and specialized security content with device access controls. You do this by creating a policy that specifies the level of protection and the sites to apply the protection to.
- Enterprise sites: Allow browser-only access. This prevents users from editing and downloading files.
- Specialized security sites: Block access from unmanaged devices.
You can refer to the below workaround. Please follow the steps:
1.Navigation to the Documents library as a site admin
2.Select one root folder and click "Manage access"
3.On the Manage Access panel, click "Advanced" link
4.On the Permissions Settings page, click "Stop Inheriting Permissions" button
5.Grant Edit permission to the specific visitor
6.Please run the below PowerShell script as an admin:
$SiteURL = "https://domain.sharepoint.com/sites/sitename"
$ListName = "xxxx"
$FolderURL = "/xxxx/yyyy"
Connect-PnPOnline -Url $SiteURL –Credentials (Get-Credential)
#$Folders = Get-PnPFolder -List $ListName
$Folders = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderURL -ItemType Folder
foreach($Folder in $Folders)
{
$FolderRelativeUrl = $FolderURL+"/"+$Folder.Name
#$FolderRelativeUrl
$FolderItems = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderRelativeUrl -ItemType File
#Write-host "Total Number of Items in the Folder in the list:" $FolderItems.Count
if($FolderItems.Count -ne 0)
{
#Write-host "Folder Name:" $Folder.Name
foreach($Item in $FolderItems)
{
if($Item.Name -like "*.xlsx")
{
Write-host "File Title:" $Item.Name
$FileItem = get-pnpfile $FilePath -AsListItem
Write-host "File ID:" $FileItem['ID']
$FilePath = $Item.ServerRelativeUrl
Write-host "File URL:" $FilePath
Write-host -ForegroundColor Cyan " ************************************************************ "
Write-host " "
Set-PnPListItemPermission -List $ListName -Identity $FileItem['ID'] -User '******@domain.onmicrosoft.com' -RemoveRole 'Edit'
}
}
}
}
7.Here is my test:
- a.Excel files delete the specific visitor's permission
- b.These Excel files cannot be seen when accessing the Documents library as the specific visitor
Thanks,
Echo Du
==================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.