PowerShell Script to give full control NTFS permissions on a directory to the domain user with the same name of that directory

#script to give full control NTFS permissions on a directory to the domain user with the same name of that directory

#script settings

$domain = “DOMAIN”
$root = “d:\home”

#don’t edit below here
$folders = Get-ChildItem $root

ForEach ($folder in $folders)
{

$folder_path = $root + “\” + $folder
$username = $domain+“\” + $folder
$permissions = Get-Acl $folder_path
$userpermissions = New-Object System.Security.AccessControl.FileSystemAccessRule($username,“FullControl”, “ContainerInherit, ObjectInherit”, “None”, “Allow”)
$permissions.AddAccessRule($userpermissions)

Set-Acl $folder_path $permissions
Write-Host “Set permissions on $folder for $username”

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s