So long story short, someone has added permissions at the top level of the Home Drive folder for some users and access has been given to home drives that shouldn’t have been. I’m trying to clean it up.<\/p>\n
I have the below test folder, it’s stripping back the rights as I want to the bear minimum. The user is given full rights on the folder and inheritance disabled<\/p>\n
$FolderPath = \"\\\\location\\c$\\HomeDrives\"\n\nWrite-Host \"#Adding global Permissions #\" -ForegroundColor Green\n\nforeach ($homeFolder in (Get-ChildItem $FolderPath | Where {$_.psIsContainer -eq $true})) {\n $homefolder\n $acl = Get-Acl $homefolder.FullName \n $acl.Access | %{$acl.RemoveAccessRule($_)} \n $acl.SetAccessRuleProtection($True, $False) \n $Rights = [System.Security.AccessControl.FileSystemRights]::FullControl\n $inherit = [System.Security.AccessControl.FileSystemAccessRule]::ContainerInherit -bor [System.Security.AccessControl.FileSystemAccessRule]::ObjectInherit\n $Propagation = [System.Security.AccessControl.PropagationFlags]::None\n $Access = [System.Security.AccessControl.AccessControlType]::Allow\n $acct = New-Object System.Security.Principal.NTAccount(\"Builtin\\Administrators\") \n $acl.SetOwner($acct) \n Set-Acl $homefolder.FullName $acl\n}\n\nWrite-Host \"#Adding user specific Permissions #\" -ForegroundColor Green\n\nforeach ($homeFolder in (Get-ChildItem $FolderPath | Where {$_.psIsContainer -eq $true})) {\n $homeFolder\n $acl = Get-Acl $homefolder.FullName\n $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($homefolder.Name,\"FullControl\", \"ContainerInherit, ObjectInherit\", \"None\", \"Allow\")\n $acl.AddAccessRule($rule)\n Set-Acl $homefolder.FullName $acl\n}\n<\/code><\/pre>\n
Advertisement
I now want the user to be the owner based off the folder name i.e. johnb is the folder name, johnb is the owner.<\/p>\n
And I also want to give local Administrators and SYSTEM full access.<\/p>\n
So end game should be: the user, local administrators to the file server and SYSTEM have full access, inheritance is disabled.<\/p>\n
Script - https://gallery.technet.microsoft.com/scriptcenter/Reset-Home-Folder-Share-a4b42fc5/view/Discussions#content<\/a><\/p>","upvoteCount":4,"answerCount":4,"datePublished":"2020-02-21T14:49:13.000Z","author":{"@type":"Person","name":"bsod","url":"https://community.spiceworks.com/u/bsod"},"suggestedAnswer":[{"@type":"Answer","text":"So long story short, someone has added permissions at the top level of the Home Drive folder for some users and access has been given to home drives that shouldn’t have been. I’m trying to clean it up.<\/p>\n
I have the below test folder, it’s stripping back the rights as I want to the bear minimum. The user is given full rights on the folder and inheritance disabled<\/p>\n
$FolderPath = \"\\\\location\\c$\\HomeDrives\"\n\nWrite-Host \"#Adding global Permissions #\" -ForegroundColor Green\n\nforeach ($homeFolder in (Get-ChildItem $FolderPath | Where {$_.psIsContainer -eq $true})) {\n $homefolder\n $acl = Get-Acl $homefolder.FullName \n $acl.Access | %{$acl.RemoveAccessRule($_)} \n $acl.SetAccessRuleProtection($True, $False) \n $Rights = [System.Security.AccessControl.FileSystemRights]::FullControl\n $inherit = [System.Security.AccessControl.FileSystemAccessRule]::ContainerInherit -bor [System.Security.AccessControl.FileSystemAccessRule]::ObjectInherit\n $Propagation = [System.Security.AccessControl.PropagationFlags]::None\n $Access = [System.Security.AccessControl.AccessControlType]::Allow\n $acct = New-Object System.Security.Principal.NTAccount(\"Builtin\\Administrators\") \n $acl.SetOwner($acct) \n Set-Acl $homefolder.FullName $acl\n}\n\nWrite-Host \"#Adding user specific Permissions #\" -ForegroundColor Green\n\nforeach ($homeFolder in (Get-ChildItem $FolderPath | Where {$_.psIsContainer -eq $true})) {\n $homeFolder\n $acl = Get-Acl $homefolder.FullName\n $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($homefolder.Name,\"FullControl\", \"ContainerInherit, ObjectInherit\", \"None\", \"Allow\")\n $acl.AddAccessRule($rule)\n Set-Acl $homefolder.FullName $acl\n}\n<\/code><\/pre>\nI now want the user to be the owner based off the folder name i.e. johnb is the folder name, johnb is the owner.<\/p>\n
And I also want to give local Administrators and SYSTEM full access.<\/p>\n
So end game should be: the user, local administrators to the file server and SYSTEM have full access, inheritance is disabled.<\/p>\n
Script - https://gallery.technet.microsoft.com/scriptcenter/Reset-Home-Folder-Share-a4b42fc5/view/Discussions#content<\/a><\/p>","upvoteCount":4,"datePublished":"2020-02-21T14:49:13.000Z","url":"https://community.spiceworks.com/t/resetting-folder-permissions-on-home-drives/752358/1","author":{"@type":"Person","name":"bsod","url":"https://community.spiceworks.com/u/bsod"}},{"@type":"Answer","text":"Root folder… shares–> domain users full permissions
\nNTFS–> Block Inheritance domain admin full access
\nmove users folder under it
\nor
\nhttps://community.spiceworks.com/scripts/show/4157-bulk-update-and-create-ad-users-home-folder-with-permissions<\/a><\/p>","upvoteCount":1,"datePublished":"2020-02-21T15:18:56.000Z","url":"https://community.spiceworks.com/t/resetting-folder-permissions-on-home-drives/752358/2","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"I wouldn’t recommend full rights for users, in my experience the “smart” users will change perms preventing things like backups to correctly execute.<\/p>\n
Had a senior exec do this and then one day several months later come to us and ask for us to restore his files as he had “accidently” deleted key documents required for a meeting that morning - the outcome was he complained to the CEO when we advised there were no files to restore for his folder due to him stripping all permissions except his own.<\/p>","upvoteCount":0,"datePublished":"2020-02-23T00:30:40.000Z","url":"https://community.spiceworks.com/t/resetting-folder-permissions-on-home-drives/752358/3","author":{"@type":"Person","name":"fids74gf","url":"https://community.spiceworks.com/u/fids74gf"}},{"@type":"Answer","text":"