使用“1”参数调用“SetAccessRule”的异常:::Powershell 错误

Jus*_*ohn 2 powershell

我的 Powershell 脚本出现错误,我试图在其中提供一个文件夹“完全控制”。我可以为域/用户帐户提供完全控制权,但我似乎无法让它为 ComputerName\Users 帐户工作。这对于允许安装的其他软件在我们组织中的各种计算机上运行很重要(它们在“安全”选项卡中都有一个 ComputerName\Users 帐户)。我想将完全控制权授予 [ComputerName\Users] 帐户。

下面的屏幕截图显示了我的脚本可以创建的 DomainUsers/Account,在它下面我无法以任何方式引用 ComputerName\Account 来提供 Total Control -- 在本例中,“Users(OHAIBMG00B7KP\Users)”触发错误。

安全标签丝印

此脚本用于为文件夹创建帐户和总控制权限

$directory = "C:\Program Files (x86)\CAREWare"
$domainName = "DHS"
$group = 'Domain Users'
$inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"
$propagation = [system.security.accesscontrol.PropagationFlags]"None"
$acl = (Get-Item $directory).GetAccessControl("Access")
$user = "{0}\{1}" -f "$domainName", $group
$user.trim()
$access = "FullControl"
$accessType = "Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList @("$user","$access", "$inherit", "$propagation", "$accessType")
$acl.SetAccessRule($accessRule)
set-acl $directory $acl
Run Code Online (Sandbox Code Playgroud)

这是我尝试更改以下三行以引用 ComputerName\Users 时出现的错误。

$directory = "C:\Program Files (x86)\CAREWare"
$domainName = $env:computername
$group = 'Users'

Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity references could not be translated."
At line:1 char:1
+ $acl.SetAccessRule($accessRule)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IdentityNotMappedException
Run Code Online (Sandbox Code Playgroud)

我似乎无法让 PowerShell 找到并返回有关 ComputerName\Users 组的任何信息,但它位于文件夹属性的安全选项卡中。

小智 5

在搜索错误消息时,这里此处此处Some or all identity references could not be translated都提出类似的问题,答案是您必须使用 SID 而不是在创建. SID 可以通过 检索。COMPUTER\UsersFileSystemAccessRuleGetPrinicpalBySamAccountName