How to Assign Authorization to User Directories on File Server with PowerShell?

The user directory E:\Personnel is located under File Server.

E:\Staff\TestUser. We create this with another script before.

TestUser folder name is also username.

We allow the user to copy files to their own folder, create folders only.

users cannot access other directories.

We give E drive read permission for Domain-Users. In the staff directory, we remove it.

$folders = Get-ChildItem -Path E:\Staff | Where-Object -FilterScript {
$_.PSIsContainer -eq $true
}

foreach ($folder in $folders)
{

$path = $folder.fullname

$path.ToString()

$username = $folder.name

$username.ToString()

$permissionArgs = “cfcu\$username”, “FullControl”, “ContainerInherit, ObjectInherit”, “None”, “allow”

$permissionRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permissionArgs

$acl = Get-Acl $path

$acl.SetAccessRule($permissionRule)

Set-ACL -Path $path -AclObject $acl

}

By:


Leave a comment