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
fannonland

 
 
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
fannonland

 
 

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
susxt

BelgiŽ
 
 

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

Thanks
My System SpecsSystem Spec
.

13 Aug 2012   #4
MFelkins

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




Similar help and support threads
Thread Forum
amending permissions on folders using powershell
Hi All I've been using the following script I found on here to create a new set of folders on our server from a txt file. However, when I run it the user is not able to add new items under the new folder. I need to be able to change the advanced security settings so that the user has full...
Software
Permissions Headache - trying to erase User folders
Hi, Trying to wipe old HD's. Erasure of the whole drive is needless waste; I just want to wipe the sensitive stuff. BUT, those permissions refuse to let go. I've searched this forum & web (long time) and tried everything: changing ownership, running as admin, every possible nook&cranny I...
General Discussion
File permissions for individual user folders, program install errors
I recently suffered a hrd disk failure and I was forced to extract the data from the faulty disk using a Linux distro (which managed to access all the files just fine while windows complained the partitions were unformatted). I then incorporated the files into my new Windows 7 installation and soon...
General Discussion
Is there a Script or batch file that can create folders by date range
I was wondering if there was a way to create a set of folders in a specific directory according to a date range that i input. ie. Select start date 2011 10 01 select end date 2012 10 01 Select Output path of c:\users\XXXX\desktop\export data
General Discussion
User Folders - Moving User Folders by Modular Script
Hi All, This script was initially made in French by Alain Quarrť, the author. I found it,lot of people too, very convenient and easy to handle so I asked the author for an english version,he kindly accepted to do the changes and agreed that I post it in this forum You can read his original...
Tutorials


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 06:08.
Twitter Facebook Google+