windows - 权限的 Power Shell 脚本不断覆盖以前的脚本
问题描述
我有两个非常相似的权限脚本,它们不断相互覆盖。当这两个脚本授予对同一文件夹的权限时,只有主管或后勤组才能获得它(我执行的最后一个脚本。
主管.ps1
$dir = "E:\test\template\"
$acl = Get-Acl $dir
$permissions2 = 'Supervisors', 'ReadAndExecute,Write', 'ContainerInherit,ObjectInherit', 'None', 'Allow'
$permissions3 = 'Supervisors', 'ReadAndExecute', 'ContainerInherit,ObjectInherit', 'None', 'Allow'
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permissions3
$acl.SetAccessRule($accessRule)
$acl | Set-Acl "$dir\01.Offers\02.Out\01.Main_Offer\02.Draft"
$acl | Set-Acl "$dir\01.Offers\02.Out\01.Main_Offer\03.Sent"
$acl | Set-Acl "$dir\01.Offers\02.Out\01.Main_Offer\04.Approved"
$acl | Set-Acl "$dir\01.Offers\02.Out\02.Additional_offers\01.Add_offer_1"
$acl | Set-Acl "$dir\02.Projects\01.Drawings"
$acl | Set-Acl "$dir\02.Projects\02.BoQ"
$acl | Set-Acl "$dir\03.Documents\01.Request_for_Offer"
$acl | Set-Acl "$dir\03.Documents\06.Other"
$acl | Set-Acl "$dir\04.Contracts"
$acl | Set-Acl "$dir\08.Logistics"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permissions2
$acl.SetAccessRule($accessRule)
$acl | Set-Acl "$dir\01.Offers\01.In"
$acl | Set-Acl "$dir\01.Offers\02.Out\01.Main_Offer\01.Calc"
$acl | Set-Acl "$dir\02.Projects\03.Reports"
$acl | Set-Acl "$dir\03.Documents\02.Schedules"
$acl | Set-Acl "$dir\03.Documents\03.Reports"
$acl | Set-Acl "$dir\03.Documents\04.Protocols"
$acl | Set-Acl "$dir\03.Documents\05.Construction_Programs"
$acl | Set-Acl "$dir\06.Correspondence"
$acl | Set-Acl "$dir\07.Pictures"
物流.ps1
$dir = "E:\test\template"
$acl = Get-Acl $dir
$permissions = 'Logistics', 'ReadAndExecute,Write', 'ContainerInherit,ObjectInherit', 'None', 'Allow'
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permissions
$acl.SetAccessRule($accessRule)
$acl | Set-Acl "$dir\01.Offers\01.In"
$acl | Set-Acl "$dir\01.Offers\02.Out\01.Main_Offer\01.Calc"
$acl | Set-Acl "$dir\02.Projects"
$acl | Set-Acl "$dir\03.Documents\04.Protocols"
$acl | Set-Acl "$dir\06.Correspondence"
$acl | Set-Acl "$dir\07.Pictures"
$acl | Set-Acl "$dir\08.Logistics"
$permissions1 = 'Logistics', 'ReadAndExecute', 'ContainerInherit,ObjectInherit', 'None', 'Allow'
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permissions1
$acl.SetAccessRule($accessRule)
$acl | Set-Acl "$dir\01.Offers\02.Out\01.Main_Offer\04.Approved"
$acl | Set-Acl "$dir\01.Offers\02.Out\02.Additional_offers\01.Add_offer_1\03.Approved"
$acl | Set-Acl "$dir\03.Documents\02.Schedules"
$acl | Set-Acl "$dir\03.Documents\03.Reports"
解决方案
您是否尝试过AddAccessRule而不是 SetAccessRule?
SetAccessRule方法添加指定的访问控制列表 (ACL) 规则或覆盖与规则参数的 FileSystemRights 值匹配的任何相同 ACL 规则。
推荐阅读
- oracle - 在不引起竞争条件和性能的情况下,基于 select 更新表的最快方法是什么?
- google-apps-script - Google Classroom API - 权限被拒绝
- sqlite - Flask-SQLAlchemy:如何更改表结构?
- c# - Environment.Exit(int) 会用运行非托管代码的踏板杀死我的应用程序吗?
- css - 被主要内容隐藏的响应式菜单
- pandas - 按 ID 和时间创建索引 - Pandas
- python - 如何通过python将csv文件内容导入excel
- python - 在远程 mlflow 服务器上保存工件
- arduino - 使用中断 ARDUINO 时出现错误消息
- html - 将内部面板控件放入 asp.net