Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script NTFS Permissions with Powershell Cmdlet Set-Acl

$
0
0

Hi,

I´m trying to script a auto permission script with powershell, which reads foldernames, searches the appropriate group in Active Directory and writes NTFS permission on that directory.

The Script looks like:

Clear-Host
$Path = "\\SERVERNAME\PATH"
# Ordnername in Array
$Foldernames = @(Get-ChildItem -Directory -Name $Path) 
#AD-Gruppe suchen nach Ordnername
foreach ($Element in $Foldernames) {    $Group = Get-ADgroup -Filter * -Properties * | `    where { $_.name -like "R-filer1*$Element*"}        $Write = [System.Security.AccessControl.FileSystemRights]'CreateFiles, WriteExtendedAttributes, WriteAttributes, Delete, ReadAndExecute, Synchronize'    $Inheri = [System.Security.AccessControl.InheritanceFlags]'ContainerInherit, ObjectInherit'    $Propag =  [system.security.accesscontrol.PropagationFlags]'None'    $Access = [System.Security.AccessControl.AccessControlType]'Allow'    $Rule = New-Object System.Security.AccessControl.FileSystemRights($Group, $Write, $Inheri, $Propag, $Access)    $ACL = Get-Acl $Path\$Element    $ACL.AddAccessRule($Rule)    Set-Acl -AclObject $ACL -Path $Path\$Element
}

The groups are found a stored to the variables, but i still can´t manage it to write NTFS permissions on the directory´s.

Getting following errror:
New-Object : Constructor not found. Cannot find an appropriate constructor for type System.Security.AccessControl.FileSystemRights.
At Permissions.ps1:21 char:13+     $Rule = New-Object System.Security.AccessControl.FileSystemRights($Group, $W ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : ObjectNotFound: (:) [New-Object], PSArgumentException    + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand 
Exception calling "AddAccessRule" with "1" argument(s): "Value cannot be null.
Parameter name: rule"
At Permissions.ps1:24 char:5+     $ACL.AddAccessRule($Rule)+     ~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException    + FullyQualifiedErrorId : ArgumentNullException

Thanks in advance !




Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>