
C:\Windows\Installer フォルダ/ファイルへのグループを拒否する必要があります
私は以下を使用しようとしましたが、それはフォルダにのみ適用され、すべてのファイルには適用されず、一部のファイルに適用されます
$path = "C:\Windows\Installer"
$acl = Get-Acl $path
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("YourUsers","FullControl", "ContainerInherit,ObjectInherit", "None", "Deny")
$acl.AddAccessRule($AccessRule)
Set-Acl -AclObject $acl -Path $path
私のスクリプトに何か欠けているものはありますか
編集: 削除できるファイルの権限を確認したところ、継承が無効になっているようです
継承が無効かどうかを確認し、無効になっている場合は有効にするにはどうすればいいですか
これを5000台のマシンに適用する必要があるので、スクリプトを使用して実行しています。
答え1
ACL の変更は で指定したフォルダーにのみ適用されます。$path
フォルダー内のすべてのものに ACL を適用するには、各項目を再帰的にリストする必要があります。
$path = "C:\Windows\Installer"
$items = Get-ChildItem -Recurse $path
# Enables inheritance on all items in folder
foreach ($item in $items)
{
$acl = Get-acl $item.FullName
$acl.SetAccessRuleProtection($false,$true)
Set-Acl -AclObject -Path $item.FullName
}
# Sets file / folder permission to desired state
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("YourUsers","FullControl", "ContainerInherit,ObjectInherit", "None", "Deny")
foreach ($item in $items)
{
$acl = Get-acl $item.FullName
# Compare item's folder permission against root folder, if different apply ACL
if ((Compare-Object -ReferenceObject (Get-ACL $path) -DifferentObject (Get-ACL $item) -Property access) -ne $null)
{
$acl.AddAccessRule($AccessRule)
Set-Acl -AclObject $item.FullName
}
}