prodigy7
prodigy7

Reputation: 83

Check in powershell permission string is valid

I try to implement a script which changes folder structure permission depending on some conditions. So far I set permissions with

    $accessRule = New-Object  System.Security.AccessControl.FileSystemAccessRule("$($group.Name)", @("$($group.Value.rights)"), "ContainerInherit, ObjectInherit", "None", "$($group.Value.type)")
    $aclFolder.AddAccessRule($accessRule)
    Set-Acl $folder $aclFolder

So far it works. But the script currently assumes, that a permission does exist. It it does not, the AddAccessRule command throws and error.

Is there any way recognize a permission exists?

Upvotes: 0

Views: 388

Answers (1)

TobyU
TobyU

Reputation: 3918

Use Get-Acl $folder to read the current ACL and to verify if there are any permissions applied already.

Upvotes: 1

Related Questions