Morning All,
I have been setting up this little script that pulls user accounts in from a csv file and then creates the folders accordingly. That bit works.
However, Setting the ACL is another matter!? All I'm after doing is putting that user account on to Modify and remove a group called Students so that said user has access but no other students do.
Heres the code
#Locators
$Domain = "NAC.local"
$Server = "\\truenas\MusicFiles\Script"
$NAS = "\\truenas\MusicFiles\Script\Intake 20$Intake\$User"
$Users = Get-Content C:\Temp\Users.csv
#Script Start
cls
Set-Location $Server
#Intake Year Creation
Write-Output "Creating new users folders, Please provide intake year (Example: 21Jblogs is 21)"
$Intake = Read-Host -Prompt 'Intake year'
New-Item "Intake 20$Intake" -ItemType directory
cd "Intake 20$Intake"
#Student Home Drive for TrueNas
ForEach ($user in $Users)
{ $sam = $User
If (Test-Path $NAS -PathType Container)
{Write-host "$sam already exists"} Else {New-Item -path $NAS -ItemType directory -Force}
#Permissions Section
Write-Output "Now setting permissions, please wait...."
$acl = Get-Acl -Path $NAS
#Access Rules Inherited from Parent Folders
$acl.SetAccessRuleProtection($true, $false)
$perm_user = "$domain\$user",@('Modify'), "ContainerInherit,ObjectInherit","None","Allow"
$userpermissions = New-Object System.Security.AccessControl.FileSystemAccessRule($perm_user)
$acl.AddAccessRule($userpermissions)
Set-ACL "$NAS" $acl }Write-Output "Folder Creation Completed."Pause
CSV File basically uses first column and each row for the username
Anyone possibly tell me what the heck is going on!