2
嗨我想給域用戶完全訪問PowerShell的文件夾。我正在使用從Technet和博客的研究中收集的這組代碼。我仍然有問題。Powershell - 設置文件夾權限
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變量,以便可以傳遞用戶參數,而不是硬編碼。
謝謝
我肯定會去'$ ENV:USERDOMAIN'(用戶)或'(gwmi的Win32_ComputerSystem).Domain',而不是'Win32_NTDomain' –
(機)謝謝致命的,百吉餅。這段代碼適用於我也需要的東西。 – JustJohn