lurezero
asked on
Powershell script - set folder permissions
I have a Windows 2008 file server. I have the following share
D:\Folder1 > this folder is shared to domain users with "list folder contents only"
Reason: Directory structure inside Folder1 is company standard.
Inside D:\Folder1
\UserFolder1
\UserFolder2
\UserFolder3
.
.
.
\UserFolder200
Permissions to be set on each subfolder: disallow inheritable permissions from parent. Then set the modidy permission for each folder.
So i found this powershell script to do this. However i cant seem to understand what could be inside c:\folders.txt. i am thinking it could be some kind of permission statement
Also can you explain the foreach loop?
I am learning powershell now and i have had to refresh my mind scripting which i havent done in a long time.
Script:
========================== =====
for ($i=1;$i-le200;$i++)
{
New-Item ('c:\Folder1\UserFolder' + $i) -type directory
}
$Users = Get-Content 'C:\Folders.txt'
# grabs the ACL from the model folder created to duplicate acl to folders 1-200
$acl = Get-Acl ('C:\Folder1\Model')
ForEach ($user in $users)
{
$newPath = Join-Path "C:\Folder1\" -childpath $user
$acl | Set-Acl $newPath
}
D:\Folder1 > this folder is shared to domain users with "list folder contents only"
Reason: Directory structure inside Folder1 is company standard.
Inside D:\Folder1
\UserFolder1
\UserFolder2
\UserFolder3
.
.
.
\UserFolder200
Permissions to be set on each subfolder: disallow inheritable permissions from parent. Then set the modidy permission for each folder.
So i found this powershell script to do this. However i cant seem to understand what could be inside c:\folders.txt. i am thinking it could be some kind of permission statement
Also can you explain the foreach loop?
I am learning powershell now and i have had to refresh my mind scripting which i havent done in a long time.
Script:
==========================
for ($i=1;$i-le200;$i++)
{
New-Item ('c:\Folder1\UserFolder' + $i) -type directory
}
$Users = Get-Content 'C:\Folders.txt'
# grabs the ACL from the model folder created to duplicate acl to folders 1-200
$acl = Get-Acl ('C:\Folder1\Model')
ForEach ($user in $users)
{
$newPath = Join-Path "C:\Folder1\" -childpath $user
$acl | Set-Acl $newPath
}
ASKER
so i am guessing the folders.txt contains a list of users? or group?
what would be the syntax?
what would be the syntax?
Yes. List of users login IDs. Just one per line:
User1ID
User2ID
etc...
User1ID
User2ID
etc...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
so if folders.txt contained:
apples
oranges
the first time in the foreach loop
$users will be apples
second time $users will be oranges
...