Hi I want to give Domain Users full access to a folder with PowerShell. I am working with this set of code gleaned from research using Technet and blogs. I am still having issues.
I am getting this error when I run the code just below:
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
Here is my code:
$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
I have tried replacing the $user variable with "domain\Domain Users" and the code works as expected. I have been unable to figure out how to pass the $user variable correctly so that the user parameter can be passed and not hard coded.
Thanks