I have a CSV file that containts a Folder Name (first 6 characters) and a User Name (rest of characters). I have to give Full Control Access to each User in His Folder. So I wrote the:
我有一个CSV文件,其中包含文件夹名称(前6个字符)和用户名(其余字符)。我必须为他的文件夹中的每个用户提供完全控制访问权限。所以我写了:
$Doc = import-csv "C:\Temp\ListOfUsers.csv"
foreach ($x in $Doc)
{
$x = ""+ $x
$CPayID = $x.SubString(10,6)
$UserName = $x.SubString(17, $x.Length-18)
$UserPath = "C:\XPAY_FTP_CUST\"+$CPayID
$Acl = Get-Acl $UserPath
$Rule = New-Object System.Security.AccessControl.FileSystemAccessRule("$Username","FullControl","ContainerInherit, ObjectInherit","None","Allow")
$Acl.SetAccessRule($Rule)
Set-Acl $UserPath $Acl
}
But I received the following Error for Each User:
但是我收到了每个用户的以下错误:
Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity references could not be translated."
使用“1”参数调用“SetAccessRule”的异常:“部分或全部身份引用无法转换。”
The Users exist and are locals, I am local administrator, and when I ask for echo the $Username
, the $UserPath
, and the $Acl
I receive correct data. Please, I need any help.
用户存在并且是本地人,我是本地管理员,当我要求回显$ Username,$ UserPath和$ Acl我收到正确的数据。拜托,我需要任何帮助。
2 个解决方案
#1
0
You might have to specify the username as DOMAIN\user
. In case of local users, DOMAIN
will be the computer name:
您可能必须将用户名指定为DOMAIN \ user。如果是本地用户,DOMAIN将是计算机名称:
$UserReference = New-Object System.Security.Principal.NTAccount $env:ComputerName,$Username
$Rule = New-Object System.Security.AccessControl.FileSystemAccessRule($UserReference,"FullControl","ContainerInherit, ObjectInherit","None","Allow")
#2
-1
Mathias is much, much smarter than I am at this, but I noticed this in your code: ($UserReference,"FullControl","ContainerInherit, ObjectInherit","None","Allow")
Mathias比我更聪明,但是我在你的代码中注意到了这一点:($ UserReference,“FullControl”,“ContainerInherit,ObjectInherit”,“None”,“Allow”)
Should "ContainerInherit, ObjectInherit"
instead be "ContainerInherit", "ObjectInherit"
?
“ContainerInherit,ObjectInherit”应该是“ContainerInherit”,“ObjectInherit”吗?
#1
0
You might have to specify the username as DOMAIN\user
. In case of local users, DOMAIN
will be the computer name:
您可能必须将用户名指定为DOMAIN \ user。如果是本地用户,DOMAIN将是计算机名称:
$UserReference = New-Object System.Security.Principal.NTAccount $env:ComputerName,$Username
$Rule = New-Object System.Security.AccessControl.FileSystemAccessRule($UserReference,"FullControl","ContainerInherit, ObjectInherit","None","Allow")
#2
-1
Mathias is much, much smarter than I am at this, but I noticed this in your code: ($UserReference,"FullControl","ContainerInherit, ObjectInherit","None","Allow")
Mathias比我更聪明,但是我在你的代码中注意到了这一点:($ UserReference,“FullControl”,“ContainerInherit,ObjectInherit”,“None”,“Allow”)
Should "ContainerInherit, ObjectInherit"
instead be "ContainerInherit", "ObjectInherit"
?
“ContainerInherit,ObjectInherit”应该是“ContainerInherit”,“ObjectInherit”吗?