4

I am trying to apply a bunch of metadata to a bunch of files in SPO. Using Find-PnPFile I can find the files in the subfolders. What I cannot figure out is how to pass the results of the Find-PnPFile back to Set-PnPListItem to set the values of the documents. I don't have the Identity of the file. What would be AMAZING is if there is a way to do this in a batch so I don't have to update every item one after another. It just feels like there should be a way to pass an array of document IDs and the value I want to set.

$updatefiles = Find-PnPFile -Folder "Documents/$($_.Name)" -Match "*"
foreach ($file in $updatefiles){
  Set-PnPListItem -List "Documents" -Values @"MMSField"="foo|bar|$($folder.Name)"} -Identity <<HELP>>
}
0

try

$childItems = Get-ChildItem -FolderSiteRelativeUrl $folderURL;
foreach($childItems in $childItems)
{
    Set-PnPListItem -List "Documents" -Values @"MMSField"="foo|bar|$($folder.Name)"} -Identity
}
0

Think of document library metadata as a list. This is what I use:

Connect-PnPOnline -url $siteURL -UseWebLogin
$DocLibName = "<NameOfDocLib>"
$Allfiles = Get-PnPListItem -List $DocLibName
foreach( $file in $Allfiles)
{
    if($file.FieldValues.<Existing_x0020_Column> -eq "<Some Value>"){
        Set-PnPListItem -List $DocLibName -Identity $file.Id -Values @{"Column_x0020_Key" = "New Value"; "Second_x0020_Column_x0020_Key" = "New Value"}
    }
}

Connect-PnPOnline: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/connect-pnponline?view=sharepoint-ps

Get-PnPListItem: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnplistitem?view=sharepoint-ps

Set-PnPListItem: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnplistitem?view=sharepoint-ps

  • As the question states, I need to use Find-PnPFiles I cannot enumerate every file in the library. – Matthew McDermott Jun 22 '18 at 14:19
  • Sorry I missed the fact you cannot enumerate every file. Still you need to access the list item, and not the file. PnP handles them as two separate things. You cannot get the file, then use that object to update the list. The link I provided for Get-PnPListItem outlines how to get by ID. – Steige Jun 25 '18 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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