Upload files to SharePoint Library with Metadata
Create the SharePoint library metadata columns
A PowerShell with SharePoint tutorial
has several methods to
upload files from Windows Explorer to a document library,
but if you want to do it automatically, you should use a
PowerShell script. In earlier articles, we have seen how
do create such a script and how set a task to run it automatically.
In such a scenario, you can put all files that should be
uploaded in a specific folder and then they will be uploaded
automatically to the SharePoint document library of your
choice. All uploaded files are moved to a subfolder, so
that they will not be uploaded to the library again.
The demo below is the first of three where Peter Kalmström
explains how metadata can be kept when you upload files
to SharePoint. The metadata he uses as an example comes
from a Windows Explorer folder named CVs. This folder has
three subfolders: Hired, Maybe and No. A file's placement
in one of those folders gives us the first keyword.
The files are all named in a consistent way, so the file
names can be used to extract three more keywords for each
file: first name, last name and department.
We of course want to have the metadata distributed into
SharePoint library columns, so the first step is to create
a new SharePoint library and add relevant columns to it.
Earlier in this tips series, we have shown several PowerShell
scripts for app creation, among them a
general script for creation of any kind of apps. Here
Peter also uses the cmdlet Add-PnPField and specifies four
columns for metadata. In PowerShell, "field" is almost always
used instead of "column".
New-PnPList -Title "CVs" -Template DocumentLibrary -OnQuickLaunch -EnableVersioning
Add-PnPField -List "CVs" -DisplayName "Decision" -InternalName "CVDecision" -Type Choice -Choices "Yes","No","Maybe"
Add-PnPField -List "CVs" -DisplayName "First
Name" -InternalName "CVFirstName" -Type Text
Add-PnPField -List "CVs" -DisplayName "Last
Name" -InternalName "CVLastName" -Type Text
Add-PnPField -List "CVs" -DisplayName "Department" -InternalName "CVDepartment" -Type Text
Note that Peter enters both display names and internal names
in the code. The internal names will be used in next demo,
where he analyzes the metadata and structures it in a way
that makes it possible to add it to the correct SharePoint
To add the new columns to the default views, add the parameter
AddToDefaultView to the Add-PnPField rows in the script.
In the demo, Peter adds them manually.
next article, we will structure the metadata go make
it possible to add to the ¨library columns we have created
You will find more detailed explanations in