Problem Statement: Bulk create Document Sets with attachment from an excel worksheet.
Summary :
Is there a way to do this via the SharePoint Online UI?
What I have understood is that to do this I need to create a PowerShell script.
After creating the content type manually in SharePoint online, I have been successful in creating the Document Sets __
through a PowerShell script__ from the exel sheet**.**
However, I am unable to update the metadata values through PowerShell after creating the Document Sets.
Also, I cannot add the attachments.
Detailed Description of steps:
I want to automate bulk creation of Document Sets with attachments in SharePoint from an excel worksheet where
- Each column in excel worksheet indicates a metadata name, and each row represents one document set
- Each row is a document set, where the values in under corresponding columns are the values of metadata.
- Values under a column named Name is the Name of the Document Set thus created
- Additionally there is a column indicating a sub folder. All files under this sub folder need to go as attachments to the Document Set.
- I created a content type in SharePoint online with Site columns(metadata).
- I have written a PowerShell script to add a document set for each row in the excel using Add-PnPDocumentSet for the given content type
- However, despite setting the values of the metadata the values don't seem to be updated in the Document Sets.
- I have tried several ways of doing this, but to no avail.
- Tried by using the internal or the external names of the metadata columns( site columns).
- Trying to get the subsite, the folder doesn't work,
- Likewise unable to find a way toadd attachments
So, I need help in updating the metadata values in the Document Sets through the PowerShell script and also add the attachments from the folder. Plese find snippet from my script below. Some of the ways I tried are commented.
Any cmdlets or code snippets I can look into?
foreach ($row in $excelData) {
# Create a document
$documentSetName = $row.Name
$documentSet = Add-PnPDocumentSet -List $documentLibrary -ContentType "Lab95" -Name $documentSetName
# The above works
#$addedDS = $web.GetFolder($documentSet)
#Write-Host " addedDS: $addedDS"
# Tried getting folder but didn't work
#and the below code doesn't work. Here I am trying with internal names of site columns. Tried with visible names #too
foreach($key in $row.keys)
{
#$documentSet.Metadata[$key] = $row.$key
#$addedDS.SetProperty($key,$row.$key)
....
if ($key -eq "Date Created"){
$newkey = "_DCDateCreated"
}
if ($key -eq "Issuer"){
$newkey = "VccIssuer"
}
...
if ($key -eq "Version"){
$newkey = "_Version"
}
$documentSet.Folder.Properties[$newkey]=$row.$key
}
$documentSet.Folder.Update()
#$list.Update()
#$web.Update()
#$subfolderpath = Join-Path -Path $inputPath -ChildPath $documentSetName
# Get the subfolder path based on the "Name" column value
$subfolderPath = Join-Path -Path $inputPath -ChildPath $documentSetName
# Attach files from the subfolder to the document set instance
$files = Get-ChildItem -Path $subfolderPath
#Tried myriad ways to add attachments and later commented none of them work
#foreach ($file in $files) {
#Add-PnPTaxonomyField -List $documentLibrary -DisplayName "Attachments" -InternalName "Attachments" -IsMulti "True" -Group "Custom Columns"
#$attachmentField = Get-PnPField -List $documentLibrary -Identity "Attachments"
#$attachmentFieldId = $attachmentField.Id
#$attachmentFileInfo = [Microsoft.SharePoint.Client.FieldLookupValue]@{ LookupId = $documentSetInstance.Id }
#$attachmentFileInfo = $attachmentField.GetFieldValueAsHtml($attachmentFileInfo)
#Add-PnPFileToContentType -List $documentLibrary -Id $attachmentFieldId -Folder "/" -Values $attachmentFileInfo -Path $file.FullName -NewFileName $file.Name
#Add-PnPTeamsTab -ListName $documentLibrary -Folder $documentSet["FileDirRef"] -SourceFilePath $file.FullName
#}