function set-rights ($path) { $p = Get-Item $path; if ($p.Attributes -eq 'Directory') { foreach ($child in Get-ChildItem $p.FullName) { set-X($child.FullName); } } icacls $p.FullName /grant 'everyone:f'; } $path="E:abc"; set-rights($t);