Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: powershell script to create user folders and set permissions

18 Nov 2010   #1

 
 
powershell script to create user folders and set permissions

Wondering if anyone in this forum can help me figure out what I am doing wrong with my script. I am grabbing a text file with a list of users in it. I want to then create folders for all those people and then set explicit permissions on those folders to only allow the users and admin access to it. So for the create user folder, I have...

$Users = Get-Content "C:\Users.txt"
ForEach ($user in $users)
{
$newPath = Join-Path \\mycomputer\Users$ -childpath $user
New-Item $newPath -type directory
}

This works great as I now have 100 folders created. But how do I use something like....

$acl = Get-Acl "\\mycomputer\users$"
$permission = "mydomain\$users","FullControl","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl \\mycomputer\users$\$user

When I try to loop these together it says the folder already exists or the setaccessrule identity references could not be translated.

Anyone know how I loop it in with creating the folder? Or is there a way to just say...create folder based on this username, then take that username and make it the only admin on the folder along with the system admin??


My System SpecsSystem Spec
.

18 Nov 2010   #2

 
 

answered my own problem...but maybe someone can help me out from here. This works for creating folders and setting permissions.

$Users = Get-Content "C:\Users.txt"
ForEach ($user in $users)
{
$newPath = Join-Path "\\myserver\Users$" -childpath $user
New-Item $newPath -type directory

$acl = Get-Acl $newpath
$permission = "mydomain\$user","FullControl","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $newpath
}

Anyone know how I would then look at an old server with user folders and do a stare and compare between the old and the new ones I just created? And once I find a folder that matches I want to grab all the contents in the old server and robocopy it over to the new server.
My System SpecsSystem Spec
09 Jul 2012   #3

BelgiŽ
 
 

What does the users.txt-file looks like?
I'm a powershell-newby ;-)

Thanks
My System SpecsSystem Spec
.


13 Aug 2012   #4

Windows 7 Home Premium x64
 
 

"Anyone know how I would then look at an old server with user folders and do a stare and compare between the old and the new ones I just created?"

Have you looked at Beyond Compare fromm Scooter Software. It was designed to do just what you are asking.

Beyond Compare - The file compare, folder compare and remote directory compare utility from Scooter Software
My System SpecsSystem Spec
Reply

 powershell script to create user folders and set permissions




Thread Tools




Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 11:38 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33