I am using Powershell to (bulk) Add-SPOFile
to a Sharepoint Online Doclib. I need to Set-SPOListItem
properties for the new items in the process, but don't know how to get the Item ID for the newly added file.
It would be great if Add-SPOFile
returned an ID, or to be able to pipe from Add-SPOFile
to Set-SPOListItem
?
What is the prescribed solution?
I am reading a CSV file, looping through the 288K entries, uploading a file for each entry, then trying to update the item properties. My code looks like this:
Connect-SPOnline -Url https://XXX.sharepoint.com/sites/sedatest -Credentials 'YYY'
$CSVPath = "ZZZ\SODA_CSVData.10.txt"
$SrcPath = "\\MDWeb01\DC\pdf\Released"
$DstFolder = "./SEDA"
$SODAData = import-csv $CSVPath -Delimiter "|"
Foreach ($r in $SODAData)
{
$UploadFile = "$SrcPath\$($r.Series.Substring(0,1))\$($r.Filename)"
Write-Host "Uploading $UploadFile"
Add-SPOFile -Path $UploadFIle -Folder $DstFolder
$Item = Get-SPOListItem -List SEDA | where {$($_.FileLeafRef) -eq $($r.Filename)}
Set-SPOListItem -List SEDA -Identity $($Item.Id) -Values @{"LegacyID" = $r.LegacyID}
}
View Source on the doc library suggests that "FileLeafRef" is the right property name:
"ID": "51",
...
"FileLeafRef": "pf2363010800.pdf",
...
Maybe I am not referencing it properly?