So I needed to remove the inheritance of a folder. Yes its easy to do with icacls, just icacls /inheritance:e|d|r. Where E is enable, D is copy all ACEs and R removes all inherited rights. But this is about doing it with powershell.
$folder = 'C:\Temp'
$acl = Get-ACL -Path $folder
$acl.SetAccessRuleProtection($True, $True)
Set-Acl -Path $folder -AclObject $acl
Thats all.. But what happened.. lets break it up.
Assigned a folder path to a variable called $folder Read the rights of the folder and saved in the variable $acl Remove the inheritance but copy the ACEs Set the ACL to the folder so its done.
So that is the $True, $True part. Well The first part says is this folder protected or not (opposite of inherited). The second is should the current ace be copied. So if you set the first to $False inheritance will be restored.