[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

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
0
mikeydk
Asked:
mikeydk
  • 3
1 Solution
 
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
 
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

Featured Post

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now