TransWikia.com

How to clone the metadata of documentA and set on documentB?

SharePoint Asked on February 21, 2021

We are using SharePoint Online. I have some document library with Word documents. I created some logic where I convert a Word document to PDF. I would like to write some logic in powershell to clone the metadata of the Word document and set on the PDF document. How to this? Is this for example possible with pnp powershell?

Something like this:

#get metadata of documentA
$documentA = Get-PnPListItem -List "TestKH" -Id 1 -Fields "Title","DocumentStatus"

#set metadata of documentB
Set-PnPListItem -List "TestKH" -Identity 2 -Values $documentA.FieldValues

One Answer

The file metadata of automatically generated by System can not be cloned to another file. For example: GUID, ID, File Size.

I suggest you can create MS Flow to achieve your design.

—————————————————— Updated Answer ————————————————

Execute the following PowerShell script to copy the file metadata to another document.

enter image description here

  • Get the data of the FileA:

    $SiteURL= "https://test.sharepoint.com/sites/projects"

    Connect-PnPOnline -Url $SiteURL -UseWebLogin

    $LibName = "Documents"

    $Fields = Get-PnPField -List $LibName

    $FileA= (Get-PnPListItem -List $LibName -Id 38 -Fields "ID","Title","FileStatus","Body")

    Write-Host ""

    Write-Host "ID :"$FileA["ID"] -ForegroundColor Yellow

    Write-Host "Title :"$FileA["Title"]

    Write-Host "Status :"$FileA["FileStatus"]

    Write-Host "Body :"$FileA["Body"]

    Write-Host "—————————————————————————" -BackgroundColor Cyan

enter image description here

  • Copy data to FileB:

    Set-PnPListItem -List $LibNAme -Id 40 -Values @{"Title" = $FileA["Title"]; "FileStatus"=$FileA["FileStatus"];"Body"=$FileA["Body"]} enter image description here

Correct answer by EchoDu_MSFT on February 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP