Created
April 3, 2025 09:49
-
-
Save lukegackle/34ffc4b9d770adca74b5173edbaf8f79 to your computer and use it in GitHub Desktop.
This script will take ownership of the specified directory and all subfolders, with the specified user account, it will also apply full control permissions to all files. https://lukestoolkit.blogspot.com/2018/12/take-ownership-of-files-and-folders.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } | |
Write-Host "-------------------------------------------------" | |
Write-Host "--------------Take Ownership Script--------------" | |
Write-Host "-------------------------------------------------" | |
Write-Host "This script will take ownership of the specified" | |
Write-Host "directory and all subfolders, with the specified" | |
Write-Host "user account, it will also apply full control" | |
Write-Host "permissions to all files." | |
Write-Host "" | |
Write-Host "Script written by Luke Gackle" | |
Write-Host "-------------------------------------------------" | |
Write-Host "" | |
$username = Read-Host -Prompt "Please provide desired username" | |
$path = Read-Host -Prompt "Please provide a path" | |
if(-Not($path[0] -eq '"' -and $path[$path.Length] -eq '"')){ | |
$path = '"' + $path + '"' | |
} | |
takeown /a /r /d Y /f $path | |
icacls $path /grant ($username + ':F') /T | |
Write-Host "Process is complete" -ForegroundColor Green | |
Read-Host -Prompt "Press ENTER to continue" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment