{"id":467,"date":"2012-11-16T11:07:24","date_gmt":"2012-11-16T11:07:24","guid":{"rendered":"http:\/\/giraffeit.com\/?p=467"},"modified":"2012-11-16T11:07:24","modified_gmt":"2012-11-16T11:07:24","slug":"resethomefolders","status":"publish","type":"post","link":"https:\/\/giraffeit.com\/index.php\/2012\/11\/16\/resethomefolders\/","title":{"rendered":"Reset home folders"},"content":{"rendered":"<p>GiraffeIT have often been asked how to reset home folders. It can be quite time consuming if done manually on a range of users.<\/p>\n<p>We have found, tested and sucessfully used the following scriptlet. Its a powershell script so dont forget to allow execution.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre>#############################################################################\n# Script: Repair-HomeFolderPermissions.ps1\n# Author: Chris Brown    http:\/\/www.flamingkeys.com\n# Date: 20\/10\/2010\n# Keywords:\n# Comments:\n# Pre-Requisites: Full Control over destination folder.\n#\n# +------------+-----+---------------------------------------------------------+\n# |       Date | Usr | Description                                             |\n# +------------+-----+---------------------------------------------------------+\n# | 20\/10\/2010 | CJB | Initial Script                                          |\n# | 28\/09\/2011 | CJB | Fixed flags issue                                       |\n# +------------+-----+---------------------------------------------------------+\n#\n# DISCLAIMER\n# ==========\n# THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE\n# RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.\n#############################################################################\n\n# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\n#            Variables\n#\n# Where is the root of the home drives?\n$homeDrivesDir=\"\\uncofhomefolder\"\n# Report only? ($false = fix problems)\n$reportMode = $false\n# Print all valid directories?\n$verbose = $false\n# What domain are your users in?\n$domainName = \"something.internal\"\n#\n# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\n\n# Save the current working directory before we change it (purely for convenience)\npushd .\n# Change to the location of the home drives\nset-location $homeDrivesDir\n\n# Warn the user if we will be fixing or just reporting on problems\nwrite-host \"\"\n\nif ($reportMode) {\n Write-Host \"Report mode is on. Not fixing problems\"\n} else {\n Write-Host \"Report mode is off. Will fix problems\"\n}\n\nwrite-host \"\"\n\n# Initialise a few counter variables. Only useful for multiple executions from the same session\n$goodPermissions = $unfixablePermissions = $fixedPermissions = $badPermissions = 0\n$failedFolders = @()\n\n# For every folder in the $homeDrivesDir folder\nforeach($homeFolder in (Get-ChildItem $homeDrivesDir | Where {$_.psIsContainer -eq $true})) {\n\n # dump the current ACL in a variable\n $Acl = Get-Acl $homeFolder\n\n # create a permission mask in the form of DOMAINUsername where Username=foldername\n #    (adjust as necessary if your home folders are not exactly your usernames)\n $compareString = \"*\" + $domainName + \"\" + $homeFolder.Name + \" Allow  FullControl*\"\n\n # if the permission mask is in the ACL\n if ($Acl.AccessToString -like $compareString) {\n\n # everything's good, increment the counter and move on.\n if ($verbose) {Write-Host \"Permissions are valid for\" $homeFolder.Name -backgroundcolor green -foregroundcolor white}\n $goodPermissions += 1\n\n } else {\n # Permissions are invalid, either fix or report\n # increment the number of permissions needing repair\n $badPermissions += 1\n # if we're in report mode\n if ($reportMode -eq $true) {\n # reportmode is on, don't do anything\n Write-Host \"Permissions not valid for\" $homeFolder.Name -backgroundcolor red -foregroundcolor white\n } else {\n # reportmode is off, fix the permissions\n Write-Host \"Setting permissions for\" $homeFolder.Name -foregroundcolor white -backgroundcolor red\n # Add the user in format DOMAINUsername\n $username = $domainName + \"\" + $homeFolder.Name\n # Grant the user full control\n $accessLevel = \"FullControl\"\n # Should permissions be inherited from above?\n $inheritanceFlags = \"ContainerInherit, ObjectInherit\"\n # Should permissions propagate to below?\n $propagationFlags = \"None\"\n # Is this an Allow\/Deny entry?\n $accessControlType = \"Allow\"\n try {\n # Create the Access Rule\n $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($username,$accessLevel,$inheritanceFlags,$propagationFlags,$accessControlType)\n\n # Attempt to apply the access rule to the ACL\n $Acl.SetAccessRule($accessRule)\n Set-Acl $homeFolder $Acl\n # if it hasn't errored out by now, increment the counter\n $fixedPermissions += 1\n } catch {\n # It failed!\n # Increment the fail count\n $unfixablePermissions += 1\n # and add the folder to the list of failed folders\n $failedFolders += $homeFolder\n }\n } #\/if\n } #\/if\n} #\/foreach\n\n# Print out a summary\n\nWrite-Host \"\"\nWrite-Host $goodPermissions \"valid permissions\"\nWrite-Host $badPermissions \"permissions needing repair\"\nif ($reportMode -eq $false) {Write-Host $fixedPermissions \"permissions fixed\"}\nif ($unfixablePermissions -gt 0) {\n Write-Host $unfixablePermissions \"ACLs could not be repaired.\"\n foreach ($folder in $failedFolders) {Write-Host \" -\" $folder}\n}\n\n# Cleanup\npopd<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>GiraffeIT have often been asked how to reset home folders. It can be quite time consuming if done manually on a range of users. We have found, tested and sucessfully used the following scriptlet. Its a powershell script so dont forget to allow execution. &nbsp; &nbsp; ############################################################################# # Script: Repair-HomeFolderPermissions.ps1 # Author: Chris Brown http:\/\/www.flamingkeys.com &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/giraffeit.com\/index.php\/2012\/11\/16\/resethomefolders\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Reset home folders&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-bog"],"_links":{"self":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":0,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"wp:attachment":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}