Set directory premissions in Powershell

Hey

I have the following directory structure:

C:\Share\FirmA\AA
C:\Share\FirmB\AA
C:\Share\FirmB\CC
..

And the similar groups

GRP_FirmA_AA
GRP_FirmB_AA
GRP_FirmB_CC
..

I have apporx 60.000 folders - How to give GRP_FirmA_AA full rights to C:\Share\FirmA\AA in PowerShell? (GRP_FirmB_AA to C:\Share\FirmB\AA and so on)

Thanks in advance

Mike
LVL 1
mikeydkAsked:
Who is Participating?
 
prashanthdCommented:
Try the following...

Modify the domain name

regards
Prashanth
$domain="domain name"

$dir=Get-ChildItem c:\share\ | Where-Object { $_.PSIsContainer } |
ForEach-Object{
$fname=$_.name
Get-ChildItem $_.fullname | Where-Object { $_.PSIsContainer } | ForEach-Object{
$sfname=$_.name
$gname=$domain+"\GRP_"+$fname+"_"+$sfname
#write-host $gname
$acl = Get-Acl $_.fullname
$permission = $gname,"FullControl","ContainerInherit,ObjectInherit","None","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $_.fullname
write-host $_.fullname
}
}

Open in new window

0
 
prashanthdCommented:
Are the groups Domain groups?
0
 
prashanthdCommented:
What is the OS?

Do permissions need to be inherited?
0
 
mikeydkAuthor Commented:
Yes, its domain groups...

Windows 2008 R2 x64

The folders have to inheriet from parent folder...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.