简体   繁体   English

PowerShell:从文件中删除所有权限,包括。 应用程序包

[英]PowerShell: Remove all permissions from a file incl. APPLICATION PACKAGES

I want to remove all permissions from some Windows\System32-files, eg wuauclt.exe and wuaueng.dll.我想从一些 Windows\System32 文件中删除所有权限,例如 wuauclt.exe 和 wuaueng.dll。 Therefore I found that script:因此我找到了那个脚本:

takeown /F $file
$acl = get-acl $file
$acl.Access | % {$acl.purgeaccessrules($_.IdentityReference)}
Set-Acl -aclobject $acl -Path $file

This gives me ownership and removes all permission except those for ALL APPLICATION PACKAGES and ALL RESTRICTED APPLICATION PACKAGES.这给了我所有权并删除了除所有应用程序包和所有受限应用程序包之外的所有权限。 How am I able remove those as well per PowerShell script (not manually and without using a 3rd party tool)?我如何能够根据 PowerShell 脚本(不手动且不使用第 3 方工具)删除它们?

Thanks in advance!提前致谢!

These IdentityReference are specific.这些IdentityReference是特定的。 In fact it is an instance of [System.Security.Principal.NTAccount] and translating them to a [System.Security.Principal.SecurityIdentifier] output an error.实际上,它是[System.Security.Principal.NTAccount]的一个实例,并将它们转换为[System.Security.Principal.SecurityIdentifier] output 时出现错误。 But it is still possible to create them manually.但是仍然可以手动创建它们。 In SDDL format: SDDL 格式:

  • AC or S-1-15-2-1 for ALL APPLICATION PACKAGES ALL APPLICATION PACKAGES程序包的ACS-1-15-2-1
  • S-1-15-2-2 for ALL RESTRICTED APPLICATION PACKAGES S-1-15-2-2适用于ALL RESTRICTED APPLICATION PACKAGES受限应用程序包

You can add the following code to remove them.您可以添加以下代码来删除它们。 But I'm not sure this is a good idea to remove these rights on System files.但我不确定这是删除系统文件的这些权限的好主意。

$acl.Access | % {
    if ($_.IdentityReference.Value -imatch "APPLICATION PACKAGES") {
        try {
            $acl.PurgeAccessRules([System.Security.Principal.SecurityIdentifier]::new("S-1-15-2-2")) 
            $acl.PurgeAccessRules([System.Security.Principal.SecurityIdentifier]::new("AC"))
        } catch { }
    }
    else {
        $acl.purgeaccessrules($_.IdentityReference)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell脚本包括 VBA Excel宏 - Powershell Script incl. VBA Excel Macro Powershell 强制将 ConvertFrom-Json 输出转换为字符串,然后可以在所有字符串操作中使用,包括。 文件命名 - Powershell force convert the ConvertFrom-Json output to string which can then be used in all string operations incl. filenaming 导出完整的TFS工作项目,包括 PowerShell的历史 - export complete TFS work item incl. history with PowerShell 从所有安全组Powershell中删除所有权限 - Remove all permissions from all security groups Powershell 使用PowerShell脚本从Android清单XML文件中删除权限 - Remove Permissions from android manifest xml file with powershell script PowerShell:删除所有用户对目录的所有权限 - PowerShell: Remove all permissions on a directory for all users powershell 删除特定用户对文件夹的所有权限 - powershell remove all permissions on a folder for a specific user 删除文件的所有权限,文件的所有者除外 - Remove all permissions to a file, except the owner of the file 如何通过Powershell从文件夹中的所有文本文件中删除某些单词? - How to remove some words from all text file in a folder by powershell? 如何使用 PnP Powershell 删除所有列表项权限 - How to remove all list item permissions using PnP Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM