powershell - Script to Create Home Drives -


i trying create small script creates folder on our file server, creates share, sets acls on share, maps share u: drive via home folder in active directory.

the server running 2012 r2, active directory powershell module installed.

this have far:

$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: 

i read using enter-pssession command doesn't allow remote commands pass through, , instead needed use invoke-command -scriptbatch.

it telling me share created, though not. ideas?

you don't need remote session of commands, provided rsat installed on client (so set-aduser available locally). new-smbshare can run against remote host using -cimsession parameter.

however, recommend against sharing each userhome individually. instead share folder containing userhomes (e.g. \\fileserver\userhomes$) , set home directory user folder below share:

$user = read-host 'input username'  $userhome = new-item -name $user -type directory -path "\\fileserver\userhomes$"  $acl = get-acl -path $userhome.fullname $acl.setaccessruleprotection($true, $true) $perm = $user,'fullcontrol','containerinherit','objectinherit','none','allow' $ace = new-object security.accesscontrol.filesystemaccessrule $perm $acl.setaccessrule($ace) $acl | set-acl -path $userhome.fullname  import-module activedirectory set-aduser $user -homedirectory $userhome.fullname -homedrive 'u:' 

enable access-based enumeration on share present users folders can access.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -