title: Script to Create Home Drives
body: <p>I am trying to create a small script that creates a folder on our file server, creates the share, sets the ACLs on the share, then maps the share to their U: drive via Home Folder in Active Directory.</p>
  
  <p>The server is running 2012 R2, the Active Directory PowerShell Module is installed.</p>
  
  <p>This is what I have thus far:</p>
  
  <pre><code>$session = new-pssession -ComputerName fileserver
  Enter-PSSession $session
  $user = read-host 'Input username'
  import-module activedirectory
  new-item -name $user -itemtype Directory -path "\\fileserver\G$" | out-null
  new-smbshare -name "$user$" -path "G:\$user" -ContinuouslyAvailable $true -FullAccess "domain\domain admins" -changeaccess "domain\$user"
  Set-ADuser $user -homedirectory "\\fileserver\$user$" -homedrive U:
  </code></pre>
  
  <p>I read using the <code>Enter-PSSession</code> command doesn't allow remote commands to pass through, and that instead you needed to use <code>Invoke-Command -ScriptBatch</code>.</p>
  
  <p>It is telling me the share is already created, even though it is not. Any ideas?</p>