I have a directory which I want to go through recursively and set permissions on all the folders. So the order of operations should be:
Use SetAccessRuleProtection() to disable inheritance and remove inherited ACEs:
$acl.SetAccessRuleProtection($true, $false)
Use RemoveAccessRule() to remove existing (non-inherited) ACEs:
$acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) | Out-Null }
Use AddAccessRule() to add new ACEs:
$ace = New-Object Security.AccessControl.FileSystemAccessRule "user", ...
$acl.AddAccessRule($ace)
...
Do this only for the topmost folder. Leave inheritance enabled everywhere below, so your changes are propagated automatically.