嗨,我想给域名用户与PowerShell文件夹的完全访问权限。我正在使用这组代码,这些代码是通过Technet和博客研究收集的。我还是有一些问题。
当我运行下面的代码时,我得到了这个错误:
Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity references could not be translated."
At line:13 char:1
+ $acl.SetAccessRule($accessRule)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IdentityNotMappedException下面是我的代码:
$directory = "C:\inetpub\wwwroot\app.webservice"
$domainName = (gwmi Win32_NTDomain).DomainName
$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 我尝试将$user变量替换为"domain\Domain Users“,代码按预期工作。我一直不知道如何正确地传递$user变量,这样才能传递user参数,而不是硬编码。
谢谢
发布于 2015-11-17 22:35:18
检查DomainName变量的值。这意味着$user变量包含类似MyDomain OtherDomain\Domain Users的内容。
如果可能,我建议将该域声明为$domainName = "MyDomain"。如果您确实需要动态获取域,则需要测试数组;
$domainName = (gwmi Win32_NTDomain).DomainName
if ($domainName -is [array]) { $domainName = $domainName[0] }注意:我的域名是按字母顺序排在第一位的,所以我不知道是先显示当前域名还是按字母顺序显示它们。您需要测试并找到适合您的解决方案。
编辑:看起来$domainName = $env:USERDOMAIN可能会做到这一点
https://stackoverflow.com/questions/33759092
复制相似问题