PowerShell_Scripts
PowerShell_Scripts copied to clipboard
PowerShell 6 version of Set-Owner
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 ('[email protected]')
$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)"
UPDATE:
I realize now that your Set-Owner solves some "un-foreseen issues": https://learn-powershell.net/2014/06/24/changing-ownership-of-file-or-folder-using-powershell/