Welcome › Forums › General PowerShell Q&A › Folder Permissions with Powershell error
This topic contains 3 replies, has 3 voices, and was last updated by
-
AuthorPosts
-
May 24, 2017 at 11:35 am #71404
Hi Guys,
I'm quite new to powershell and trying to use the Get-ACL and set-acl cmdlets to change a folder permission on a new folder.
i have set a $paste for the username so for example would be jack.smith
i am trying to create the folder with
FileSystemRights : DeleteSubdirectoriesAndFiles, Modify, Synchronize
AccessControlType : Allow
IdentityReference : USERNAME
IsInherited : False
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : Nonebut i get an error when trying to create a permissions object like below:
PS C:\Users\xxxxx> $Perms = New-Object system.security.accesscontrol. filesystemaccessrule("$paste$","DeleteSubdirectoriesAndFiles","Modify","Synchron ize","ContainerInherit","ObjectInherit") New-Object : Cannot find an overload for "FileSystemAccessRule" and the argumen t count: "6". At line:1 char:20 + $Perms = New-Object < <<< system.security.accesscontrol.filesystemaccessrule ("$paste$","DeleteSubdirectoriesAndFiles","Modify","Synchronize","ContainerInhe rit","ObjectInherit") + CategoryInfo : InvalidOperation: (:) [New-Object], MethodExcept ion + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power Shell.Commands.NewObjectCommand any help would be great!
-
May 24, 2017 at 11:57 am #71408
Check out Rohn Edwards's PowerShell Access Control module, it automates a lot of what could be tedious to do manually with the native cmdlets..
-
May 24, 2017 at 2:49 pm #71419
Done it! thanks for the suggestion, it seems overly complicated compared to the module you linked me to 🙂
-
-
May 24, 2017 at 3:08 pm #71429
The problem you are having is some of the parameters to the FileSystemAccessRule constructor are a collection and you don't have them together (e.g., 'ContainerInherit','ObjectInherit' vs. 'ContainerInherit, ObjectInherit')
Try using this code snippet instead:
# https://msdn.microsoft.com/en-us/library/sfe70whw(v=vs.110).aspx $Perms = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList ( "$paste$", 'Modify', 'ContainerInherit, ObjectInherit', 'Allow')
-
AuthorPosts
The topic ‘Folder Permissions with Powershell error’ is closed to new replies.