Alexander Meise
Alexander Meise

Reputation: 1438

How can I add Localhost\Users + READ permissions to a folder in Powershell

I tried:

$Folderpath='D:\DATA\'
$user_account='USERS'
$Acl = Get-Acl $Folderpath
$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule($user_account, "Read", "ContainerInherit, ObjectInherit", "None", "Allow")
$Acl.Setaccessrule($Ar)
Set-Acl $Folderpath $Acl

I get following error:

Set-Acl : The security identifier is not allowed to be the owner of this object.

I do not want USERS to be the owner tho, only to have READ.

Upvotes: 0

Views: 270

Answers (1)

henrycarteruk
henrycarteruk

Reputation: 13227

If you use the File System Security PowerShell Module this task becomes much easier as you can use Add-NTFSAccess, which acts in a much more logical manner:

Add-NTFSAccess -Path D:\DATA -Account 'LocalComputerName\Username' -AccessRights Read

And if it's a Domain Group just replace LocalComputerName with the Domain Name.

Upvotes: 1

Related Questions