$domainName = \"Domain\\\"\n$folders = get-childitem | foreach {if($_.PSIsContainer){$_.fullname}}\n\nForEach ($folder in $folders){\n $folderName = (Get-Item $folder).name\n $userName = $folderName\n $PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None\n $InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit\n $objType = [System.Security.AccessControl.AccessControlType]::Allow\n $permission = \"$domainName$userName\",\"FullControl\",$InheritanceFlag,$PropagationFlag,\"Allow\"\n $accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $permission\n \n icacls.exe $folder /reset\n $acl = Get-ACL $folder\n $acl.SetAccessRule($accessRule)\n $acl | Set-ACL $folder \n}\n<\/code><\/pre>\nI hope this helps someone!<\/p>","upvoteCount":0,"datePublished":"2017-11-20T14:52:07.000Z","url":"https://community.spiceworks.com/t/permissions/619412/7","author":{"@type":"Person","name":"christopherwhiteley2344","url":"https://community.spiceworks.com/u/christopherwhiteley2344"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hey Spiceheads,<\/p>\n
I am banging my head up against the wall for what should be an easy thing. I am looking at user folder permissions and trying to make it very specific. My goal is this:<\/p>\n
Each User folder will have these permissions: \nDomain\\Domain Admins \nLocal\\Administrators \nDomain%username%<\/p>\n
What is the easiest way to do this so that I can make this happen? I have searched and everyone seems to have a different way of doing things. I have the “everyone” for the share as Full as that doesn’t matter.<\/p>\n
I have done the “create” function in GP under user configuration > Preferences > Windows Settings > Folders and checked the “Run in logged on users Security Context”<\/p>","upvoteCount":4,"datePublished":"2017-11-17T22:00:29.000Z","url":"https://community.spiceworks.com/t/permissions/619412/1","author":{"@type":"Person","name":"christopherwhiteley2344","url":"https://community.spiceworks.com/u/christopherwhiteley2344"}},{"@type":"Answer","text":"\n\n
<\/div>\n
christopher4:<\/div>\n
\nDomain%username%<\/p>\n<\/blockquote>\n<\/aside>\n
Don’t do this. never assign users to folders with direct permissions. Put users into folders and assign the folders the permissions.<\/p>","upvoteCount":2,"datePublished":"2017-11-17T22:59:48.000Z","url":"https://community.spiceworks.com/t/permissions/619412/2","author":{"@type":"Person","name":"Gary-D-Williams","url":"https://community.spiceworks.com/u/Gary-D-Williams"}},{"@type":"Answer","text":"
I understand for shared folders, but I am doing their own personal folders that get mapped as a drive and I don’t want anyone else stumbling across them.<\/p>","upvoteCount":1,"datePublished":"2017-11-17T23:05:21.000Z","url":"https://community.spiceworks.com/t/permissions/619412/3","author":{"@type":"Person","name":"christopherwhiteley2344","url":"https://community.spiceworks.com/u/christopherwhiteley2344"}},{"@type":"Answer","text":"
Home folders, if done manually, can just have system, admin and the user. No need for local admin permissions on server shares.<\/p>","upvoteCount":0,"datePublished":"2017-11-18T03:58:21.000Z","url":"https://community.spiceworks.com/t/permissions/619412/4","author":{"@type":"Person","name":"lewandowski","url":"https://community.spiceworks.com/u/lewandowski"}},{"@type":"Answer","text":"
That’s exactly what I want but I don’t want to do it manually. I want to create a script to do this for me. That’s the reason for this post. <\/p>","upvoteCount":0,"datePublished":"2017-11-18T05:11:56.000Z","url":"https://community.spiceworks.com/t/permissions/619412/5","author":{"@type":"Person","name":"christopherwhiteley2344","url":"https://community.spiceworks.com/u/christopherwhiteley2344"}},{"@type":"Answer","text":"
I have done something similar to this , I created a batch file using ICALS “Drive:\\Path” /grant username:(OI)(CI)M.<\/p>","upvoteCount":0,"datePublished":"2017-11-20T12:44:07.000Z","url":"https://community.spiceworks.com/t/permissions/619412/6","author":{"@type":"Person","name":"scottbrindley","url":"https://community.spiceworks.com/u/scottbrindley"}}]}}
Hey Spiceheads,
I am banging my head up against the wall for what should be an easy thing. I am looking at user folder permissions and trying to make it very specific. My goal is this:
Each User folder will have these permissions:
Domain\Domain Admins
Local\Administrators
Domain%username%
What is the easiest way to do this so that I can make this happen? I have searched and everyone seems to have a different way of doing things. I have the “everyone” for the share as Full as that doesn’t matter.
I have done the “create” function in GP under user configuration > Preferences > Windows Settings > Folders and checked the “Run in logged on users Security Context”
4 Spice ups
christopher4:
Domain%username%
Don’t do this. never assign users to folders with direct permissions. Put users into folders and assign the folders the permissions.
2 Spice ups
I understand for shared folders, but I am doing their own personal folders that get mapped as a drive and I don’t want anyone else stumbling across them.
1 Spice up
Home folders, if done manually, can just have system, admin and the user. No need for local admin permissions on server shares.
That’s exactly what I want but I don’t want to do it manually. I want to create a script to do this for me. That’s the reason for this post.
I have done something similar to this , I created a batch file using ICALS “Drive:\Path” /grant username:(OI)(CI)M.
So I ended up figuring this out and I can hopefully help other people with this. What I did was to follow this person’s advice on setting the permissions at the top folder:
Hello. I have recently run into an issues with our user folders. I'm trying to remove a particular group from each user folder but wanting to keep that group in the parent folder. There are 410 user folders that i do not want to manipulate manually. Is there a way to do this with powershell?
Thanks in advance
Then I found this powershell script that would add just the user based on foldername with the full control permissions. I just placed this Powershell script inside of the folder that I needed permissions on. This worked for me!
$domainName = "Domain\"
$folders = get-childitem | foreach {if($_.PSIsContainer){$_.fullname}}
ForEach ($folder in $folders){
$folderName = (Get-Item $folder).name
$userName = $folderName
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$objType = [System.Security.AccessControl.AccessControlType]::Allow
$permission = "$domainName$userName","FullControl",$InheritanceFlag,$PropagationFlag,"Allow"
$accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $permission
icacls.exe $folder /reset
$acl = Get-ACL $folder
$acl.SetAccessRule($accessRule)
$acl | Set-ACL $folder
}
I hope this helps someone!