Jump to content

Powershell (2012 R2) - Altering homeshare permissions


Recommended Posts

Posted

I'm in the process of migrating to a new server, the existing setup didnt include individual permissions for each user. I would like to add them to the new server. We have our users home folder named the same as the user and would like to do the following with each one.

 

Add the user Read/Write/Modify to their own documents

Enable inheritance for all below this folder

Not to delete existing permissions.

 

Instead of me starting from the begining does anyone have a powershell (2012 r2) script they use.

Posted
easiest way ive found is to create the folder structure you want except the user folders then go to a bunch of users and change their homeshare to whatever you want so \\server\users$\staff\%username% and it will create all the folders with correct permissions then just drag and drop data back into users areas
Posted
#----Config Area-------------------

#Enter the Domain Name

$domain = “domain”

#Enter the root of the share

$root = “F:\Documents\Students\08\”

 

#----------------------------------

$folders = Get-ChildItem $root

 

ForEach ($folder in $folders)

 

{

#Create a var with the domain and username

$username = $domain+“\”+$folder

#Create a var with the full path the folder

$fullfolderpath = $root+$folder

#Get current acl of the folder

$acl = Get-Acl $fullfolderpath

#create a rule of permissions you would like to add

$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($username, "DeleteSubdirectoriesAndFiles, Modify, Synchronize", "ContainerInherit, ObjectInherit", "None", "Allow")

$acl.AddAccessRule($rule)

#Add acl rule to path

Set-Acl -Path $fullfolderpath -AclObject $acl

}

 

I've created a powershell to add the permissions, it's from the last hour of learning so may be rubbish. It doesn't contain any error handling either. It seems to add the correct permissions.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...