首页 > 解决方案 > 权限的 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"

标签: windowspowershell

解决方案


您是否尝试过AddAccessRule而不是 SetAccessRule?

SetAccessRule方法添加指定的访问控制列表 (ACL) 规则或覆盖与规则参数的 FileSystemRights 值匹配的任何相同 ACL 规则。


推荐阅读