title: Batch Powershell User csv import and home folder creation
body: <p>I'm trying to use a CSV import to create batch users but for it to also create users' home folder and profile folders but with setting permissions at the same time.</p>
  
  <p>I've found a lot of helpful information online, I just don't know how to make the syntax work with what I already have which took me quite a long time to even get to.</p>
  
  <p>This is my script so far for creating accounts on the domain controller and then syncing them with O365. We use a csv as we create tons of users at the same time:</p>
  
  <pre><code>Import-Csv "C:\blablabla\filename.csv" | ForEach-Object { 
  New-ADUser -Name $_.Name `
   -GivenName $_."GivenName" `
   -Surname $_."Surname" `
   -DisplayName $_."DisplayName" `
   -SamAccountName  $_."samAccountName" `
   -UserPrincipalName  $_."UserPrincipalName" `
   -Path $_."Path" `
   -AccountPassword (ConvertTo-SecureString “Pa$$w0rd” -AsPlainText -force) -Enabled $true `
   -EmailAddress $_."EmailAddress" `
   -ProfilePath $_."ProfilePath" `
   -HomeDrive $_."HomeDrive" `
   -HomeDirectory $_."HomeDirectory" `
   -ScriptPath $_."ScriptPath" `
   -Server $_."Server" `
   -OtherAttributes @{ProxyAddresses= $_."ProxyAddresses"} `
  }
  Start-ADSyncSyncCycle -PolicyType Initial
  </code></pre>
  
  <p>All the values point to columns in the excel file which auto-complete based on a user's first and last name.</p>
  
  <p>I know I'm supposed to be creating the home and profile folders and setting permissions as per the below for example, I just don't know how to make the syntax work with what I already have?</p>
  
  <p>So far, the values only get set in AD correctly but the folders don't get created and permissions aren't getting applied.</p>
  
  <p>I guess I could just add an other command to create a new folder but I wouldn't know how to do append that to the foreach command? </p>
  
  <pre><code>New-Item -ItemType Directory -Path \\dc\userdata
  $ACL = (Get-ACL -Path $HomeDirectory)
  $FullControlAccessRule = (New-Object System.Security.AccessControl.FileSystemAccessRule([System.Security.Principal.NTAccount]"hcc.local\$UserName","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))
  $ACL.AddAccessRule($FullControlAccessRule)
  Set-ACL -Path $HomeDirectory $ACL
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks.</p>
  
  <p>So, as per what NAS said, something like this then</p>
  
  <pre><code>?
  
   -OtherAttributes @{ProxyAddresses= $_."ProxyAddresses"}
   New-Item -ItemType Directory -Path $_.HomeDirectory           
   New-Item -ItemType Directory -Path $_.ProfilePath             
   $ACL = (Get-ACL -Path $_.HomeDirectory)                       
   $FullControlAccessRule = (New-Object System.Security.AccessControl.FileSystemAccessRule(
                                  [System.Security.Principal.NTAccount]"hcc.local\$($_.samAccountName)",        
                                  "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))
      $ACL.AddAccessRule($FullControlAccessRule)
      Set-ACL -Path $_.HomeDirectory $ACL
   $ACL = (Get-ACL -Path $_.ProfilePath)                       
   $FullControlAccessRule = (New-Object System.Security.AccessControl.FileSystemAccessRule(
                                  [System.Security.Principal.NTAccount]"hcc.local\$($_.samAccountName)",        
                                  "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))
      $ACL.AddAccessRule($FullControlAccessRule)
      Set-ACL -Path $_.ProfilePath $ACL
  </code></pre>