Link to home
Start Free TrialLog in
Avatar of thaapavuori
thaapavuoriFlag for Finland

asked on

Trying to set ACL via PowerShell to UNC path

I'm trying to set ACL via powershell. My script is here:

$acl = Get-Acl $folder
$permission = "domain\$user","FullControl","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $folder

This $folder variable content is UNC path.

When I run this script I get error message:
Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity references could not be translated."
At C:\temp\FTPUser.ps1:50 char:19
+ $acl.SetAccessRule <<<< ($accessRule)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

What I have done incorrectly?

Thanks
Avatar of Bryan Butler
Bryan Butler
Flag of United States of America image

Maybe try specifying explicitly:

$permission = $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ("users","FullControl","Allow")

Also, in your script, where is $user set?
ASKER CERTIFIED SOLUTION
Avatar of Bryan Butler
Bryan Butler
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thaapavuori

ASKER

Thanks this was woking. I was still able to use $user variable. This $user has been typed before by end user.