Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a list of permissions for a folder, I want to test if each IdentityReference in this list exist in another list consisting of IdentityReferences, if it matches do nothing, else remove permission for this IdentityReference.

Bare it mind, the above is only to describe what I am aiming to do, I already have a working code, but the problem is it is 10 lines, I want to do it all in minimum number of lines.

$perm = $acl.Access | select IdentityReference, FileSystemRights | where {$_.IdentityReference -notin @("BUILTINAdministrators", "NT AUTHORITYSYSTEM")}

Now I have to apply a user defined function to each IdentityReference in the $perm, is this possible to do all in one line?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
423 views
Welcome To Ask or Share your Answers For Others

1 Answer

try this

$perm = $acl.Access | select IdentityReference, FileSystemRights | where {$_.IdentityReference -notin @("BUILTINAdministrators", "NT AUTHORITYSYSTEM")}
$perm | %{yourfunction $_.IdentityReference}

or on the same line

$acl.Access | select IdentityReference, FileSystemRights | where {$_.IdentityReference -notin @("BUILTINAdministrators", "NT AUTHORITYSYSTEM")} | %{yourfunction $_.IdentityReference}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...