PowerShell create folder and set ACL

Viewed 25

I have a need to create a user folder for about 500 users and rather than do it manually i would like to try using PowerShell. I have an csv file with a header called folder, this holds the username i.e. tuser which is what the folder should be named once created and that username should be added to the folder ACL with modify permissions in addition to inheriting the root permissions. I tried the script below but it did nothing not even errors. Any suggestions on how to best achieve this? The end result should be a new folder \fileserver\share$\Test\tuser

location where the folders will be created Set-Location \fileserver\share$\Test

csv file with folder names $Folders = Import-Csv C:\Temp\Scripts\newusers.csv

ForEach ($Folder in $Folders) { New-Item $Folder.name -itemtype directory

1 Answers

As per my comment. I'd suggest trying something like this.

Import-Csv -Path 'C:\Temp\Scripts\newusers.csv' | 
ForEach-Object {New-Item -Path '\fileserver\share$\' -Name $PSitem -ItemType Directory -Force}
Related