Add 'Take Ownership' to context menu (PowerShell)

Introduction

This script adds 'Take Ownership' to the context menu in Windows 8.

Scenarios

When you want to delete and copy some files and folders in Windows 8, you may encounter a "you do not have permission to delete or move it” message. This occurs because you are not the owner of the file or folder. This script adds "take ownership" to the context menu so that you can easily change the owner of a file to the current user.

Script

This script contains the Set-OSCTakeOwnerShip advanced function. You can use this script in the following ways:

Method 1:

  1. Download and open the     script file by using Notepad or any other script editor.
  2. Scroll down to the end of the script     file, and then add the example command which you want to run.
  3. Save the file then run the script in PowerShell.

Method 2:

  1. Rename scriptname.ps1 to scriptname.psm1 (PowerShell Module file)
  2. Run Import-Module cmdlet to import this module file.
            Import-Module filepath\scriptname.psm1


Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.

PowerShell
Edit|Remove
If(Test-Path-LiteralPath 'HKCR:\*\shell\runas') 
{ 
    Set-Location-LiteralPath 'HKCR:\*\shell'Remove-Item-Path ".\runas"-Recurse -Confirm:$false 
} 
If(Test-Path-LiteralPath 'HKCR:\Directory\shell\runas' ) 
{ 
    Set-Location-LiteralPath 'HKCR:\Directory\shell'Remove-Item-Path ".\runas"-Recurse -Confirm:$false  
} 
If(Test-Path-LiteralPath 'HKCR:\dllfile\shell' ) 
{ 
Set-Location-Path 'HKCR:\dllfile\' 
Remove-Item-Path ".\shell"-Recurse -Confirm:$false  
} 
Set-Location (Split-Path$env:ComSpec -Parent) 
Write-Host "Remove 'Take ownership' from context menu successfully."

Examples

Example 1: Add 'Take Ownership' to context menu.
Command: Set-OSCTakeOwnerShip -Add
Screenshot:

Example 2: Remove 'Take Ownership' from context menu.
Command: Set-OSCTakeOwnerShip -Remove
Screenshot:

 

Prerequisite

Windows 8