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
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.
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
Correct answer by EchoDu_MSFT on February 21, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP