Question

I'm trying to change a folders owner by using Get-Acl and Set-Acl. The issues lies when I try to change the Get-Acl object by using .setOwner() Is this the correct way to change the objects owner property? I am currently using PS 2.0.

$DomainNameShort = "domain"
$profileName = "user_name"
$newProfileLocation = "\\server\folder"
$objUser = New-Object System.Security.Principal.NTAccount("$DomainNameShort\$profileName")
$objFile = Get-Acl $newProfileLocation
$objFile.SetOwner($objUser)
Set-Acl -aclobject $objFile -path $newProfileLocation

This is the error that I am getting:

Exception calling "SetOwner" with "1" argument(s): "Some or all identity references could not be translated
."
At line:6 char:18
+ $objFile.SetOwner <<<< ($objUser)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Any guidance would be much appreciated, thanks.

Was it helpful?

Solution

Your domain or username is incorrect.

SetOwner() can verify the identity provided with $objuser

CAUTION Be aware that using Set-Acl on a SHARE (not a folder beneath a share, but the root/share itself) can break inheritance of permissions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top