Windows PowerShell banner.

Many of the computer labs are set up as follows: the learners log into a Windows server and a script sets up the PC they are working on with their profile which includes mapping their Documents folder which is actually a directory on the server. Here is a PowerShell script that uses a CSV file as a listing to copy folders from one directory to another.

It is often necessary to copy a set of files in a folder to each of the learner’s Documents folder (for practical assessments, for example). This solution will work anywhere where you need to copy folders from one location to another.

The CSV file is simple and can be created and edited in Excel. In the following example, one folder and all its contents (in the ‘Source’ column) will be copied to the same directory with the names provided in each row as per the ‘Destination’ column. The ‘Destination’ paths can easily be manipulated using Excel to create a list of learner profile directories etc. The headings must be exactly as they are in the below screenshot.

Now for the PowerShell command. The command below is run from the same directory that contains the folder to be copied. It can be adapted as required. To easily open an instance of PowerShell SHIFT+right-click in the whitespace in the relevant directory in Windows Explorer (C:\PowershellFolderCopywork in this example)

Import-CSV "C:\PowershellFolderCopyWork\list.csv" | foreach {
Copy-item -Path $($_.source) -Destination $_.Destination -Recurse

I had hoped to use this script to copy my learners’ PAT project folders for marking, however it is not flexible enough in that I can’t know exactly what my learners have named their PAT folders.

Here is my second attempt: PowerShell script: copying PAT folders.

By foxbeefly

PHP / MySQL Developer. HTML, CSS and some JavaScript.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.