Answer the question
In order to leave comments, you need to log in
How to grant access to folders of a domain user through Powershell?
Hello. The purpose of the script is to give access to a folder for a specific user. I have been suffering for 2 days now. Found different options. But everything throws an error, supposedly not the right argument, etc.
The scheme is like this. There is a file exchanger ( folder Obmen ) . Further it is created under folders. The general path to the user's personal folder is as follows.
C:\Obmen\Sklad\Ivanov Ivan Ivanovich\Private.
It would be desirable to give the rights in such a way that the user on these folders C:\Obmen\Sklad would have read-only access.
........Ivanov Ivan Ivanovich\Personal has full access to these folders and besides him, other users, except for reading, had no access.
$newuser = (get-eventlog -log Security -InstanceID 4720 -newest 1).ReplacementStrings[9]
mkdir C:\obmen\$newou\$newfolder\Private
# Read the current ACL settings for our folder
$acl = Get-Acl C:\obmen\$newou\$newfolder\Private
# Let's see the resulting ACL
$acl | fl *
# Create a permission set that we will assign to the folder
$permission = “ADTEST0\$newuser”,”read,write",”containerinherit,objectinherit”,”none”,”allow”
# View current ACEs
$acl.Access
# Create new ACE object based on previously written permissions
$ace = new-object security.accesscontrol.filesystemaccessrule $permission
# Apply the changes made to the original ACL
$acl.setaccessrule($ace)
# Assign an ACL to the selected folder
$acl | set-aclC:\ obmen\$newou\$newfolder\Private
Answer the question
In order to leave comments, you need to log in
Use third-party modules so as not to suffer.
https://github.com/raandree/NTFSSecurity
https://github.com/alphaleonis/AlphaFS
Or this third-party command line utility - it feels great in Powershell.
https://helgeklein.com/setacl/
Hello.
Here, try this script:
$a = Get-Acl -Path C:\Temp\TestPS
$fileSystemAccessRuleArgumentList
# Тут Указываем пользователя
$identity = "NT AUTHORITY\Прошедшие проверку"
# тут доступ
$fileSystemRights = "Read"
$type = "Allow"
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
$a.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path C:\Temp\TestPS -AclObject $a
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question