{"id":141,"date":"2019-03-18T19:00:06","date_gmt":"2019-03-18T19:00:06","guid":{"rendered":"https:\/\/www.atlanta247.com\/blog\/?p=141"},"modified":"2019-11-20T16:07:04","modified_gmt":"2019-11-20T16:07:04","slug":"create-file-folder-and-permission","status":"publish","type":"post","link":"https:\/\/www.atlanta247.com\/blog\/2019\/03\/18\/create-file-folder-and-permission\/","title":{"rendered":"Create File Folder and permission"},"content":{"rendered":"\n<p>I needed a quick script to include in my runbooks &#8211; one to create the home drive for my new user process.   I got the base for this off the internet ( <a href=\"https:\/\/activedirectoryfaq.com\/2017\/09\/powershell-create-home-directory-grant-permissions\/\">https:\/\/activedirectoryfaq.com\/2017\/09\/powershell-create-home-directory-grant-permissions\/<\/a> ) but I wanted to add a little bit of checking to see if the file existed first, etc.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>param([Parameter(Mandatory=$true)][String]$samAccountName)\n\n$User = Get-ADUser -Identity $samAccountName -Properties l\n\n$office = $User.l\n\n$homePath = \"\\\\my.netork\\user$\\\" + $Office + \"\\{0}\" -f $samAccountName\n\n \nif($User -ne $Null) {\n\t\n\t#check home path to make sure one doesn't already exist\n\t[string]$homepathtest = Test-Path $homePath\n\t\n\tIf ($homepathtest -eq \"False\") \n\t\t{\n\t\t#create home drive\n\t    $homeShare = New-Item -path $homePath -ItemType Directory -force -ea Stop\n\t \t\n\t    $acl = Get-Acl $homeShare\n\t \t\n\t\t#permissison home drive\n\t    $FileSystemRights = [System.Security.AccessControl.FileSystemRights]\"Full\"\n\t    $AccessControlType = [System.Security.AccessControl.AccessControlType]::Allow\n\t    $InheritanceFlags = [System.Security.AccessControl.InheritanceFlags]\"ContainerInherit, ObjectInherit\"\n\t    $PropagationFlags = [System.Security.AccessControl.PropagationFlags]\"InheritOnly\"\n\t \n\t    $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($User.SID, $FileSystemRights, $InheritanceFlags, $PropagationFlags, $AccessControlType)\n\t    $acl.AddAccessRule($AccessRule)\n\t \n\t    Set-Acl -Path $homeShare -AclObject $acl -ea Stop\n\t \t\n\t    Write-Host (\"HomeDirectory created at {0}\" -f $homePath)\n\t\n\t\t}\n\t\t\n\tIf($homepathtest -eq \"true\") {\n\t\tWrite-Host (\"Home Directory at {0} already exists\" -f $homePath )\n\t\t}\n\t\n#\n} \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I needed a quick script to include in my runbooks &#8211; one to create the home drive for my new user process. I got the base for this off the internet ( https:\/\/activedirectoryfaq.com\/2017\/09\/powershell-create-home-directory-grant-permissions\/ ) but I wanted to add a little bit of checking to see if the file existed first, etc.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8,9,7],"tags":[15],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scsm","category-work","tag-powershell"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":2,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":143,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/posts\/141\/revisions\/143"}],"wp:attachment":[{"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.atlanta247.com\/blog\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}