PowerShell Script To Create Folders From CSV

This script will read in a csv named users.csv and create a bunch of directories from it. A log file will be written named logfile.log

###########################################################
# MODIFIED: Jack Stromberg
# DATE : 7/19/2012
# COMMENTS: $_.FirstName and $_.LastName are the column names in the csv file
###########################################################
# Get current directory and set import file in variable
$path = Split-Path -parent $MyInvocation.MyCommand.Definition
$newpath = $path + "\users.csv"
# Define variables
$log = $path + "\logfile.log"
$date = Get-Date
# FUNCTIONS
Function createDirs
{
"Created following directories (on " + $date + ") " | Out-File $log -append
"--------------------------------------------" | Out-File $log -append
Import-CSV $newpath | ForEach-Object {
$dir = $path + "\" + $_.FirstName + "." + $_.LastName + "\"
$dir = $dir.ToLower()
New-Item $dir -type directory
}
}
# RUN SCRIPT
createDirs
#Finished

Leave a Reply

Your email address will not be published. Required fields are marked *

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