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

1 Answer 1


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

  • Thank you EchoDu_MSFT, It was just an example. I dont want to clone the ID. I remove it from my example. I would like to avoid MS Flow.
    – Jackson
    Commented Jan 7, 2021 at 9:09
  • Hi, Jackson. I have updated my answer, hope this helps you. Have a nice day! Commented Jan 11, 2021 at 9:32

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.