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

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

Powershell apply a function to each member of a list

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

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

1 Answer

0 votes
by (71.8m points)

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}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...