0

I have this PnP PowerSell script to get all files which have .lock extension:-

$AllItems = Get-PnPListItem -List $Library -PageSize $BatchSize -Fields ID -ScriptBlock { Param($items) $global:counter += $items.Count; `
Write-Progress -PercentComplete ($global:Counter / ($Library.ItemCount) * 100) -Activity "Getting List Items of '$($_.Title)'" `
-Status "Processing Items $global:Counter to $($Library.ItemCount)";}  | Where {$_.FileSystemObjectType -eq "File" -and $_.FileLeafRef -like "*.lock" }
Write-Progress -Activity "Completed Retrieving Items from List $($Library.Title)" -Completed
         
#Process All Files from the Library
$global:Counter = 1
ForEach($Item in $AllItems)

But I will not get any file. Any advice?

1 Answer 1

1

Try below code to fetch .lock extension file:

$LibraryName = "Documents"
$LibraryItems = Get-PnPListItem -List $LibraryName -PageSize 500 -Fields "FileLeafRef" | Where {$_.FileSystemObjectType -eq "File" -and $_["FileLeafRef"] -like "*.lock" } 

#Get File count
Write-Host "Total Number of Items Found:"$LibraryItems.count 

#Get each File name
ForEach($Item in $LibraryItems)
{
    Write-Host $Item.FieldValues["FileLeafRef"] 
}
1
  • worked well thanks a lot
    – John John
    Commented Mar 15, 2023 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.