Forum Discussion
Frenchy81100
Nov 14, 2022Copper Contributor
Specials Get-Acl and Set-Acl rules on directories
Hello Everyone, I'm managing to create a script for a company I am working with, and unfortunately, I'm stuck. The company wants some people to only access few directories using that path m...
- Nov 15, 2022
$Data1=Get-ChildItem C:\Users\Administrateur\Software\Clients -Directory -Recurse | where-object Name -eq Direct
Does that work? I don't think the * works... Nope, it doesn't 🙂
Frenchy81100
Copper Contributor
Yes I already am the owner of all the folders and files
Nov 15, 2022
$Data1=Get-ChildItem C:\Users\Administrateur\Software\Clients -Directory -Recurse | where-object Name -eq Direct
Does that work? I don't think the * works... Nope, it doesn't 🙂
- Frenchy81100Nov 17, 2022Copper ContributorHarm_Veenstra
Thanks a lot For Everything, the script doesn't look clean but still is nice and fully working. - Nov 17, 2022Nice!
- Frenchy81100Nov 17, 2022Copper ContributorAll good! I finaly got the Answer....
Here Is the script:
$Data1=Get-ChildItem C:\Users\Administrateur\Software\Clients\ -Recurse | Where-Object -Property Name -Contains 'Direct' | Get-Acl
$Data2=Get-ChildItem C:\Users\Administrateur\Software\Clients\ -Recurse | Where-Object -Property Name -Contains 'DSS' | Get-Acl
$Data3=Get-ChildItem C:\Users\Administrateur\Software\Clients\ -Recurse | Where-Object -Property Name -Contains 'Flux' | Get-Acl
$Usergroup="Accès Fichiers"
$fileSystemRights="Read"
$InheritanceFlag="ContainerInherit,ObjectInherit"
$PropagationFlag="None"
$AccessControlType="Allow"
#Permet de désactiver l'héritage des autorisations du dossier:
$NewAcl=$Data1
$NewAcl.SetAccessRuleProtection($true,$true)
$NewAcl | Set-Acl
#Permet de donner les autorisations pour le groupe:
$Acl=$Data1
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule($Usergroup, $fileSystemRights, $InheritanceFlag, $PropagationFlag, $AccessControlType)
$Acl.addAccessrule($rule)
$Acl | Set-Acl
#Copier les autorisations sur les autres dossiers:
$NewAcl=$Data2
$NewAcl.SetAccessRuleProtection($true,$true)
$NewAcl | Set-Acl
#Permet de donner les autorisations pour le groupe:
$Acl=$Data2
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule($Usergroup, $fileSystemRights, $InheritanceFlag, $PropagationFlag, $AccessControlType)
$Acl.addAccessrule($rule)
$Acl | Set-Acl
$NewAcl=$Data3
$NewAcl.SetAccessRuleProtection($true,$true)
$NewAcl | Set-Acl
#Permet de donner les autorisations pour le groupe:
$Acl=$Data3
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule($Usergroup, $fileSystemRights, $InheritanceFlag, $PropagationFlag, $AccessControlType)
$Acl.addAccessrule($rule)
$Acl | Set-Acl
Everything all Set and works fine! - Frenchy81100Nov 17, 2022Copper ContributorLast Question over this topic, I rearranged my script and now it works fine, but I can't use the propagation flags after the System.Security.AccessControl.FileSystemRule("User","InheritOnly","Read","Allow").
I tried Changing the order and don't get any better results. I always get an error:
New-Object : Cannot find an overload for "FileSystemAccessRule" and the argument count: "4".
I don't understand why cant I put 4 arguments when normaly you can enter the user/group, ACL, Propagation and Inheritance Flags and also Acces Type... Could someone give me some help with it?
Here is The Script:
$Data1=Get-ChildItem C:\Users\Administrateur\Software\Clients\ -Recurse | Where-Object -Property Name -Contains 'Direct' | Get-Acl
$Data2=Get-ChildItem C:\Users\Administrateur\Software\Clients\ -Recurse | Where-Object -Property Name -Contains 'DSS' | Get-Acl
$Data3=Get-ChildItem C:\Users\Administrateur\Software\Clients\ -Recurse | Where-Object -Property Name -Contains 'Flux' | Get-Acl
#Permet de désactiver l'héritage des autorisations du dossier:
$NewAcl=$Data1
$NewAcl.SetAccessRuleProtection($true,$true)
$NewAcl | Set-Acl
#Permet de donner les autorisations pour le groupe:
$Acl=$Data1
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule("Accès Fichiers","InheritOnly","Read","Allow")
$Acl.addAccessrule($rule)
$Acl | Set-Acl
#Copier les autorisations sur les autres dossiers:
$NewAcl=$Data2
$NewAcl.SetAccessRuleProtection($true,$true)
$NewAcl | Set-Acl
#Permet de donner les autorisations pour le groupe:
$Acl=$Data2
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule("Accès Fichiers","InheritOnly","Read","Allow")
$Acl.addAccessrule($rule)
$Acl | Set-Acl
$NewAcl=$Data3
$NewAcl.SetAccessRuleProtection($true,$true)
$NewAcl | Set-Acl
#Permet de donner les autorisations pour le groupe:
$Acl=$Data3
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule("Accès Fichiers","InheritOnly","Read","Allow")
$Acl.addAccessrule($rule)
$Acl | Set-Acl
And The Error: (In French)
New-Object : Surcharge introuvable pour « FileSystemAccessRule » et le nombre d'arguments « 4 ».
Au caractère C:\Users\Administrateur\Documents\Bon Script.ps1:14 : 7
+ $rule=New-Object System.Security.AccessControl.FileSystemAccessRule(" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
New-Object : Surcharge introuvable pour « FileSystemAccessRule » et le nombre d'arguments « 4 ».
Au caractère C:\Users\Administrateur\Documents\Bon Script.ps1:27 : 7
+ $rule=New-Object System.Security.AccessControl.FileSystemAccessRule(" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
New-Object : Surcharge introuvable pour « FileSystemAccessRule » et le nombre d'arguments « 4 ».
Au caractère C:\Users\Administrateur\Documents\Bon Script.ps1:39 : 7
+ $rule=New-Object System.Security.AccessControl.FileSystemAccessRule(" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand - Nov 16, 2022No problem, glad to help... Please mark my answer as solution to mark this as solved 🙂
- Frenchy81100Nov 16, 2022Copper Contributor
I checked with that line:
Get-ChildItem C:\Users\Administrateur\Software\Clients\ -Recurse | Where-Object -Property Name -Contains 'Direct'
It looks like it works and showed me the Folder in the different "Clients" Folders. I need to manage it for the rest of the Script.
Thank you a lot for your good help!