1

I am working on a script to set file permissions using the ShareUtils module and for some reason it is not continuing to my second and third stage loops. Not sure why?

$input | Where-Object {$_.AccessMask -like 2032127} | Foreach-Object {
Get-Share -Name $_.Name | Add-SharePermission $_.User Allow FullControl | Set-Share
}

$input | Where-Object {$_.AccessMask -like 1245631} | Foreach-Object {
Get-Share -Name $_.Name | Add-SharePermission $_.User Allow Change | Set-Share
}

$input | Where-Object {$_.AccessMask -like 1179817} | Foreach-Object {
Get-Share -Name $_.Name | Add-SharePermission $_.User Allow Read | Set-Share
}

1 Answer 1

1

Try to reset $input. Once $input is called it processes all of its elements and moves forward until it gets to the last item.

$input.reset()

UPDATE

You could also rewrite the solution, an example would be:

$input | Foreach-Object {

    $perm = switch($_.AccessMask)
    {
        2032127 {'FullControl'; break}
        1245631 {'Change'; break}
        1179817 {'Read'; break}
    }

    if($perm)
    {
       Get-Share -Name $_.Name | Add-SharePermission $_.User Allow $perm | Set-Share        
    }       

}
Sign up to request clarification or add additional context in comments.

1 Comment

I see that. That's actually what I was looking for more than anything. Thanks Shay!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.