So obviously I am lacking all skills to build or even search for the solution to my issue. I hope there's someone here who can help me.
I need to remove the retention label on a couple of files in a SharePoint folder. The files are nested inside subfolders. I have found a script that loops through the folders and resets the label. However, the 5.000 items list view threshold of SharePoint Online prevents me from running the script smoothly.
So I came up with a solution.
First I am caching all list items into an array.
$ListItems = Get-PnPListItem -List Documents -PageSize 500
This is how an item inside this array looks like:
So now I have this.
Next, I am looping through all folders I receive only the GUID from a file (from SharePoint). Not the ID. So while I am looping through the I want to lookup the item in the array by using the GUID. I thought of using a filter action inside the foreach. Eventually, I need to have the ID value (number) of the file so I can perform a Set-PnPListItem action.
I am getting stuck at the filter action inside the foreach. I simply can't get it to work after struggling and searching for 2.5 hours.
This is what I have now:
$itemsColl=Get-PnPFolderItem -FolderSiteRelativeUrl $newFolderURL -ItemType File
foreach($ArrayItem in $itemsColl){
$GUID = $ArrayItem.UniqueId.Guid
$resultaat = $ListItems | Where {$_["FieldValues"]["GUID"] -eq $ArrayItem.UniqueId.Guid} # DOESN'T WORK
$resultaat = $ListItems | Where-Object $a = @($_.FieldValues.GUID) {$ListItems | Where-Object $a -eq $ArrayItem.FieldValues.Guid} # DOESN'T WORK
Write-Host $resultaat.FieldValues.ID
}
Unfortunately I can't get it to work. I doubt if it is because of the nested FieldValues, or that my nested $_ references won't work. I hope someone here can help me fix it!
Thanks in advance, Joost