samcbshep21 Posted August 3, 2016 Posted August 3, 2016 We have created some AD accounts and their Home Directorys through PowerShell. We are trying to make it so each user has access to their Home Directory. Using the below scrcipt we were able to get the 1st user access to their Home directory, the rest errored. If anyone could help I would be so grateful. I had never touched PowerShell until today so am a total noob.
MuttsNutts Posted August 18, 2016 Posted August 18, 2016 Hi Looking at your script I can see you have set the home path as \\SERVERNAME\STUDENTS\2016INTAKE\$USERNAME so this means your usernames match the home folder name? You can simply set permissions on user home folders via AD on mass simply selecting all students within an OU - right click - properties - profile - ticking home folder box - selecting the required drive letter your case H and type in \\SERVERNAME\STUDENTS\2016INTAKE\%USERNAME% Click apply and ok - you may get a message explaining about setting permissions if so click yes on this, even when you do it this way if the home folder does not exist it actually creates it also not script I know but hope it helps? Thanks
Davit2005 Posted August 18, 2016 Posted August 18, 2016 (edited) I use this at the end of the user creation scipt, it uses the same csv as used to create the account. $folders = import-csv CSV.csv ForEach ($row in $folders) { $SamAccountName = $row.sAMAccountName $homeDir = "\\SERVER\userhome" $homeFolderFQDN = "\\SERVER\userhome" $HomeDrive = "h:" $pre2000Domain = "DOMAIN" $HomeDirectory = "$homeFolderFQDN" + "$SamAccountName" write "Changing Permissions for $pre2000Domain\$SamAccountName on $homeFolderFQDN$SamAccountName" $acl = Get-Acl "$homeFolderFQDN$SamAccountName" $rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$pre2000Domain\$SamAccountName", "DeleteSubdirectoriesAndFiles, Modify, Synchronize", "ContainerInherit, ObjectInherit", "None", "Allow") $acl.AddAccessRule($rule) $acct=New-Object System.Security.Principal.NTAccount("$pre2000Domain\$SamAccountName") $acl.SetOwner($acct) Set-Acl "$homeFolderFQDN$SamAccountName" $acl Set-ADUser -Identity $SamAccountName -HomeDrive "$HomeDrive" -HomeDirectory "$HomeDirectory" } Edited August 18, 2016 by Davit2005
samcbshep21 Posted August 25, 2016 Author Posted August 25, 2016 Hi Looking at your script I can see you have set the home path as \\SERVERNAME\STUDENTS\2016INTAKE\$USERNAME so this means your usernames match the home folder name? You can simply set permissions on user home folders via AD on mass simply selecting all students within an OU - right click - properties - profile - ticking home folder box - selecting the required drive letter your case H and type in \\SERVERNAME\STUDENTS\2016INTAKE\%USERNAME% Click apply and ok - you may get a message explaining about setting permissions if so click yes on this, even when you do it this way if the home folder does not exist it actually creates it also not script I know but hope it helps? Thanks This is what we did in the end, we knew we could we would have just liked to get it in one script. Thanks! - - - Updated - - - I use this at the end of the user creation scipt, it uses the same csv as used to create the account. Hopefully once we get 5 minutes to try this out we will. Will update you whenever that is. Thanks!
MuttsNutts Posted August 25, 2016 Posted August 25, 2016 Samcbshep21 - glad you got the job done in the end glad I could help, this time of year is always a busy one for us IT bods in education often goes unnoticed too!
Davit2005 Posted August 25, 2016 Posted August 25, 2016 I use this module makes it a lot easier Ian Prefer my small script :-). They don't half complicate things in that Script Center. All I wanted to do was have a look at the powershell scipt before clicking on an install. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now