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
User Folder - Create Your Own Special Folders
How to Create Your Own Special User Folder I am dutch but for this tutorial I set my mui to English to make it easier on you. :D Here I have a folder called "Installatie" (that's dutch for Installation) I want to make a special folder in my username (in this case Michel on the left...
Tutorials
CMD or Powershell Moving - script not working
set LISTFOLDER=D:\List\ set FILESPATH=D:\Igre\COD-MW2\main\images set DESTPATH=D:\Igre\COD-MW2\main\images\thepit REM for /r %LISTFOLDER% %%I in (*.txt) do echo xcopy /qvs "%FILESPATH%\%%~nxI" "%DESTPATH%%%~pnxI" for /r %LISTFOLDER% %%I in (*.txt) do xcopy /qvs "%FILESPATH%\%%~nxI"...
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
PowerShell logon script
Ok, so this doesn't necessarily have to do with Windows 7, but I originally wanted to reply to a post on Vista forums and somehow I ended up here. Anyway... I actually tried all of this on Windows Server 2008 - set policies, scripts and logged on there. Here's one way that actually works. 1)...
Network & Sharing


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 08:33.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App