Upload files to SharePoint Library with Scheduled Task
A PowerShell with SharePoint tutorial
SharePoint
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 such a scenario, you can put all files that should be
uploaded in a specific folder and then they will be uploaded
to the SharePoint library of your choice when the script
is run.
In the demo below, Peter will
explain how to schedule a task that runs the script automatically.
For that, he creates a "script running" task the Task Scheduler,
which is included in Windows.
Peter uses the script from the
previous
article, where all copied files are moved to a subfolder so that they will not be uploaded to the library again.
Note that you need to use a certificate that allows modifications
to SharePoint without login, if you want to run a PowerShell
script that connects to SharePoint automatically. In an
earlier article, we described how
to create such a certificate.
- Copy the path to the .ps1 file that should run on
a schedule.
- Open the Windows Task Scheduler.
- Create a new task. In the demo, Peter uses the Basic
task option, but if you want to have more choices on
when the task should be run you can create a standard
task.
- Give the task a name.
- Set a Trigger for the task - that is, how often
(and at what time) the task should be run. In the standard
task creation you can set a few other parameters.
- Keep the default Action: Start a program.
- Enter pwsh for PowerShell 7.
- Enter the arguments –Noprofile -WindowStyle Hidden
-ExecutionPolicy Bypass -File [paste the path you copied
in step 1]
- Finish the task creation.
- Test the script by right-clicking on the task in
the Task Scheduler and selecting Run.
In the
next article, we will show how metadata can be included
in the uploaded files.
|