Question

I uploaded a file to SP library with $f = Add-PnPFile -Path "C:\temp\01.pdf" -Folder "documents"

What is best way to get the id or UniqueID of this new file? I need this info to use Set-PnPListItem command.

Était-ce utile?

La solution

Not sure why you need Set-PnPListItem after adding the file.

To add the properties of the file, you can just use the Values parameter and set them as below:

$f = Add-PnPFile -Path "C:\temp\01.pdf" -Folder "Documents" -Values
@{Title="01 Title";Description="Test description"}

Reference- Add-PnPFile

However, if you do need to use Set-PnPListItem directly after uploading the file, you can use it as below. We will first upload the file, then fetch it using the latest item id and then update it.

$f = Add-PnPFile -Path "C:\temp\01.pdf.pdf" -Folder "Documents"
$listItems = Get-PnPListItem -List "Documents"
$maxItemId = ($listItems.Id | measure-object -maximum).maximum;
Set-PnPListItem -List "Documents" -Identity $maxItemId -Values @{Title="01 Title";Description="Test description"}

or using Get-PnPFile to get list item and then update as below:

$f = Add-PnPFile -Path "C:\temp\01.pdf" -Folder "Documents"
$listItem = Get-PnPFile -Url "/sites/test/Documents/01.pdf" -AsListItem
$res = Set-PnPListItem -List "Documents" -Identity $listItem -Values @{Title="01 Title";Description="Test description"}
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top