if (-not (Test-Path "\SRV-1Disco$homePath")){
$NewFolder = New-Item -Path "\SRV-1Disco" -Name $homePath -ItemType "Directory"
$folderPath = "\SRV-1Disco$homePath"
$user = "ARZANI$($e.'username')"
# Get the current ACL (Access Control List)
$acl = Get-Acl $folderPath
# Define the new permission rule (FullControl in this example)
$permission = "FullControl"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($user, $permission, "ContainerInherit, ObjectInherit", "None", "Allow")
# Add the new rule to the ACL
$acl.SetAccessRule($accessRule)
# Apply the updated ACL to the folder
Set-Acl -Path $folderPath -AclObject $acl
# Confirm the changes
(Get-Acl $folderPath).Access
}
I tried but it return to me this error: Exception calling “SetAccessRule” with “1” argument(s): “Some or all identity references could not be translated. The folder has been created but there are not the permission for the user
New contributor
Christian Arzani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.