Top Contributors

GPO to automatically create a mapped folder for new users which created from template user.

I am looking into a setup to create users from template users in AD which automatically creates a sharefolder for the particular user as "USER_Share" which maps to user automatically. Is there any method ?? Thank you.


Expert Comment

CLR Benjamin2017-05-15 07:10 AMID: 2006494
Try this powershell script:

#import csv
Import-Csv C:\users.csv | foreach {
#create user
 $name = $
 $surname = $_.surname
 $displayname = $($surname+ " $name")
 $name = $($surname+ " $name")
 $login = $_.login
 $ou = "OU=Users,DC=contoso,DC=com"
 $password = "p@ssw0rd"
New-ADuser -surname $surname -givenname $name -displayname $displayname -organization "enterprise" -name $name -path $OU -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -userprincipalname "$" -samaccountname $login -enabled $true
#Set-aduser -Identity $login -Add @{extensionAttribute1="Example"}} #add attribute
#if you want to hide the shared folder 
# $login = $login+"$"

mkdir \\yourfileserver\$login

#set ACL
New-SmbShare –Name $login –Path \\yourfileserver\$login –FullAccess contoso\$login
$Acl = Get-Acl "\yourfileserver\$login"
$Ar = New-Object\$login,"FullControl","Allow")
Set-Acl "\\yourfileserver\$login" $Acl

Open in new window

Csv template : users.csv


Open in new window

Then create GPO,

Add a new drive mapping
1. Expand ‘User Configuration’ – ‘Preferences’
2. Right-click ‘Drive Maps‘ – ‘New‘ – ‘Mapped Drive‘
3. For ‘Action‘, select ‘Replace‘
4. In the ‘Location‘ field, type the UNC shared folder : \\yourfileserver\%username%
5. Select ‘Reconnect‘ to make sure the drive is persistent
6. Under ‘Drive Letter‘, select the letter for the user to use as the mapped network drive

Author Comment

Shamil Mohamed2017-05-17 08:04 PMID: 2007375
Thanks bro. Let me have a try...

Author Comment

Shamil Mohamed2017-05-17 08:09 PMID: 2007377

have some doubts..

1) so we have to create users.csv to create manually rite ?

2) powershell script have apply each time ?? or once only.. ??

Expert Comment

CLR Benjamin2017-05-22 06:42 AMID: 2008380
You just have to put users info in the CSV. Then launch the powershell to create user on your AD.  The powershell will proceed by loop on the CSV. So you have to erase the CSV every time. Or you can just update the CSV, powershell will just has an error when creating an existing user.