PowerShell

Fix Windows Access Denied Using PowerShell (Take Ownership + ACLs)

If you’ve ever copied files from another machine and Windows won’t let you delete them, this is why—and how to fix it properly.

Eugene Fischer Apr 22

The Root Cause

Windows security is based on:

  • SIDs (Security Identifiers), not usernames

So:

  • Same username โ‰  same identity
  • Files copied across machines retain original ownership

๐Ÿ” The Fix Strategy

We perform 3 operations:

  1. Take ownership (takeown)
  2. Modify ACL (icacls)
  3. Delete (Remove-Item)

๐Ÿงพ Script

$folder = "Z:\backups\_Windows_delete\bcastdvr"
$user = "$env:COMPUTERNAME\$env:USERNAME"

takeown /f $folder /r /d y
icacls $folder /grant "$user:(F)" /t /c
Remove-Item $folder -Recurse -Force

๐Ÿ”ฌ Command Breakdown

takeown

  • Reassigns ownership recursively

icacls

  • Modifies ACL (Access Control List)
  • (F) = Full control

Remove-Item

  • PowerShell-native recursive delete

โš ๏ธ PowerShell vs CMD Gotcha

CMDPowerShell%username%$env:USERNAME

๐Ÿงช When This Fails

  • Network drives (permissions external)
  • Read-only media
  • System-protected folders

๐Ÿ’ก Takeaway

Understanding Windows ACLs is critical when:

  • Working with backups
  • Moving files across environments
  • Debugging permission issues


โœ‰๏ธ Join the Developer Community

Get the latest insights, tutorials, and tech updates delivered straight to your inbox. No spam, just quality content for developers. Unsubscribe anytime.

Read next

Fix Windows Access Denied Using PowerShell (Take Ownership + ACLs)

If you’ve ever copied files from another machine and Windows won’t let you delete them, this is why—and how to fix it properly.

Eugene Fischer Apr 22
An unhandled error has occurred. Reload ๐Ÿ—™