我编写了一个脚本来为文件夹和子文件夹内的权限添加安全性,但并授予该用户完全权限。
当我运行脚本时,它会将用户添加到子文件夹我希望它添加到根文件夹、子文件夹以及具有完全正确权限的子文件夹内的文件,并为该用户启用继承
# Set properties
$identity = "ANC_C"
$fileSystemRights = "FullControl"
$type = "Allow"
$allFolders=Get-ChildItem -Path C:\Work\Test -Directory -Recurse
foreach ($Folder in $allFolders){
$fileSystemAccessRuleArgumentList = $identity, $fileSystemRights, $type
$fileSystemAccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $fileSystemAccessRuleArgumentList
$Permission=get-acl -Path $Folder.FullName
$Permission.SetAccessRule($fileSystemAccessRule)
Set-Acl -Path $Folder.FullName -AclObject $Permission
}
提前致谢
答案1
旧版 cmdlet Get-Acl、Set-Acl 功能不够全面,也不太好用。我建议使用名为 NTFSSecurity 的 Powershell 模块。
$Root = Get-ChildItem -Path "C:\Temp"
Add-NTFSAccess -Path $Root -Account <Domain\AccountName -AccessRights FullControl
<#
Other parameters
-AccessType : values (Allow/block) - Default value Allow, then you can ommit it
-AppliesTo ThisFolderSubfoldersAndFiles or other (see the parameterValueSet), this one is the default, you can ommit it
-PropagationFlags is InheritOnly as a default value, you can ommit it.
-PassThru : useful to see the output in the console.
```
One cmdlet to do the job. Definitivly adopted !
Hope this help
Olivier