Thursday 8 November 2018

Bulk folder creation from spreadsheet

The following PowerShell code was developed to bulk create student folders at the start of term for individual departments. By providing a .csv file a folder can be created for each student using a naming convention derived from the column headings (a convention unique to each department).
Snippet of student_folder.csv data (anonymised)
#File location of .csv
$csvPath = "C:\User Files\student_folder.csv"

#Import .csv into script
$csv = Import-CSV $csvPath

#Work through each row in turn
$csv | ForEach-Object {

    #Create a variable based on attributes from the column headings for the name
    $name = $_.LastName + " " + $_.FirstName + " " + $_.College + " " + $_.ID

    #Create main 'Student Folders' folder and then sub-folders with above name attributes
    $folderpath = "C:\User Files\Student Folders\" + $name
    New-Item $folderpath -ItemType Directory


Bulk folder creation from spreadsheet.ps1
Sample student_folder.csv

No comments:

Post a Comment