Surender
Surender

Reputation: 61

Create and Map Home Directory for AD Users using PowerShell

I used to create and map the home directory for new AD users in Active Directory Users and Computers GUI with following syntax:

\FileServer\users\%username%

This trick automatically creates home directory for user in FileServer and automatically grant full control to user on the directory. I was wondering what could be the PowerShell way of doing the same.

Upvotes: 0

Views: 3107

Answers (1)

Eldo.Ob
Eldo.Ob

Reputation: 794

I think first of all you should get the User.

$user = get-ADUser -Filter { Name -like "Mike" }

Then create a Folder New-Item, something like:

$sac = $user.SamAccountName
$folder = New-Item \\Server\Filesystem\$sac -Type Directory

And then you have to set the permissions via Set-ACL

create new acl object

$AclOb = New-Object
System.Security.AccessControl.FileSystemAccessRule("domain\$sac", 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')

The security identifier (domain$sac);The right (FullControl); Inheritance settings (ContainerInherit,ObjectInherit) which means to force all folders and files underneath the folder to inherit the permission we’re setting here; Propagation settings (None) which is to not interfere with the inheritance settings; Type (Allow).

and set-acl

Set-Acl -Path $folder.FullName -AclObject $AclOb

Greetz Eldo.Ob

Upvotes: 1

Related Questions