Skip to content

PowerShell 6 version of Set-Owner #17

Description

@jzabroski

Set-Owner does not work on PowerShell 6 due to referencing .NET Framework assembly APIs. .NET Core has refactored these APIs, and they no longer work in PowerShell 6 because the API is not there.

The following is a simpler Set-Owner script:

#
# IMPORTANT: Run with ELEVATION
#

# The target folder.
$folder = 'C:\Temp'

# Specify the new owner, which can be a mere username ('John.Doe'), a well-known
# security principal ('BUILTIN\Administrators'), or a UPN ('John.Doe@example.org')
$newOwner = 'BUILTIN\Administrators'

# Get the current ACL...
$acl = Get-Acl -LiteralPath $folder

# ... and assign the new owner...
$acl.SetOwner([System.Security.Principal.NTAccount] $newOwner)

# ... and set the modified ACL.
Set-Acl -LiteralPath $folder -AclObject $acl

"New owner: $((Get-Acl -LiteralPath $folder).Owner)"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions