I'm a new learner to Powershell and a bit new to SharePoint as well.
I'm learning powershell to create a script that uploads files to a sub-site library inside SharePoint. I managed to get it working and uploading .doc files to my library, however I also want fill in any metadata specified in additional columns with the file at the same time. I'm not using the SharePoint snap-in and instead using the webclient functions. Here is the simple powershell script
# create the Variable Path and Pass the source folder path $path = "THE FILE" # create the Variable destination and pass the URL of the SharePoint List $destination = "SharePoint SubSite" # Store the current user default credentials in the Variable Credentials $credentials = [System.Net.CredentialCache]::DefaultCredentials; # Create the object of the Webclient $webclient = New-Object System.Net.WebClient; $webclient.Credentials = $credentials; $webclient.UploadFile($destination + “/” + "Filename", “PUT”, TheFile)
This code works but there is a couple things I don't understand.
Why do I have to add + "/" and what does PUT DO? Why doesn't this (
$filename) just work?
The file uploads perfectly with the + / syntax, however I don't know how to use the webclient functions to pass in metadata to specified columns in the document library when uploading the file to the library.