General discussion

  • Creator
    Topic
  • #4126499

    Automate the changing of ownership of files and folders in Windows 10

    Locked

    by darkdata ·

    Tags: 

    I know how to manually change file/folder ownership within Windows, what I want to find out is if there is a script or other means to which when a file/folder is copied from one user to another, the ownership of the said data changes to that of the new location. Thus, manual changing is not required.

All Comments

  • Author
    Replies
    • #4126766
      Avatar photo

      Re: change ownership

      by kees_b ·

      In reply to Automate the changing of ownership of files and folders in Windows 10

      I doubt if you can download such a script. But, since it’s can be done in PowerShell, you can write your own.

    • #4127066
      Avatar photo

      Sure.

      by rproffitt ·

      In reply to Automate the changing of ownership of files and folders in Windows 10

      While I’d log in with the new user and then do a Takeown, there’s a script to do this later. Read https://learn-powershell.net/2014/06/24/changing-ownership-of-file-or-folder-using-powershell/

      For me since I deal with so many PCs at my brother’s office I use Takeown and wait a while. It’s not long and hasn’t been worth the effort to use/make anything else.

    • #4131563

      Windows 10

      by maxburns090 ·

      In reply to Automate the changing of ownership of files and folders in Windows 10

      To automate the changing of ownership of files and folders in Windows 10, you can make use of PowerShell scripts. PowerShell is a powerful scripting language that allows you to automate various tasks in Windows. Here’s an example PowerShell script that you can use to change the ownership of a file or folder.
      # Define the source and destination paths
      $sourcePath = “C:\Path\to\source\file.txt”
      $destinationPath = “C:\Path\to\destination\file.txt”

      # Get the current owner of the source file
      $sourceOwner = (Get-Item $sourcePath).GetAccessControl().Owner

      # Set the owner of the destination file
      (Get-Item $destinationPath).SetAccessControl((New-Object System.Security.AccessControl.FileSecurity).SetOwner($sourceOwner))

      n this script, you specify the source path (the file or folder that has the desired ownership) and the destination path (the location where the file or folder is copied to). The script retrieves the current owner of the source file and sets it as the owner of the destination file. You can modify the paths in the script to match your specific source and destination locations. Save the script with a .ps1 extension (e.g., change-ownership.ps1), and then you can run it by executing powershell.exe and passing the script file as an argument (e.g., powershell.exe -ExecutionPolicy Bypass -File “C:\Path\to\change-ownership.ps1”). By utilizing such a script, you can automate the process of changing ownership when copying files or folders from one user to another, eliminating the need for manual changes.

Viewing 2 reply threads