当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 清除 Windows Defender 防病毒排除项

作者:精品下载站 日期:2024-12-14 18:38:26 浏览:14 分类:玩电脑

使用 PowerShell 清除 Windows Defender 防病毒排除项


我们希望删除 Windows Defender 防病毒排除项。问题是有很多排除项,当我们进入微软病毒和威胁防护设置时,需要花费很多时间来手动删除它们。这是因为您无法选择多个排除项并将其删除。删除 Windows Defender 排除的一个绝佳方法是使用 PowerShell。因此,让我们看看使用 PowerShell 清除 Windows Defender 防病毒排除项的最快方法。

Microsoft Defender 防病毒软件

Microsoft Defender Antivirus(以前称为 Windows Defender)是 Microsoft Windows 病毒和威胁防护软件。 Microsoft Defender 防病毒软件适用于 Windows 10、Windows 11 和 Windows Server 版本。它是 Windows 操作系统的默认设置。它可以在主动模式、被动模式和禁用模式下与非 Microsoft 防病毒/反恶意软件产品一起运行。

当您转到 Windows Defender 防病毒排除项时,会显示包含所有排除项的列表。不幸的是,没有全选按钮或复选框来选择排除项并将其删除。相反,每个排除项只有一个删除按钮。

[玩转系统] 使用 PowerShell 清除 Windows Defender 防病毒排除项

准备明确的 Windows Defender 防病毒排除 PowerShell 脚本

在开始之前,您需要将文件放置在正确的位置。我们建议在(C:)驱动器上创建两个文件夹:

  • 脚本

  • 温度

下载 Clear-WindowsDefenderExcl.ps1 PowerShell 脚本并将其放置在 C:\scripts 文件夹中。该脚本会将日志导出到 C:\temp 文件夹。

确保该文件未被阻止,以防止运行脚本时出现错误。请阅读文章运行 PowerShell 脚本时出现未数字签名错误来了解更多信息。

另一种选择是将以下代码复制并粘贴到记事本中。将其命名为 Clear-WindowsDefenderExcl.ps1 并将其放置在 C:\scripts 文件夹中。

# PowerShell script to clear the ExclusionPath, ExclusionProcess, and ExclusionExtension
# associated with Windows Defender Antivirus

# Start transcript
$Logs = "C:\temp\Clear-WindowsDefenderExcl.txt"
Start-Transcript $Logs -Append -Force

# Get Windows Defender preferences
$x = Get-MpPreference

# Get exclusion path
if ($x.ExclusionPath -ne $NULL) {
    Write-Host("================================================")
    Write-Host("Removing the following ExclusionPath entries:")
    foreach ($i in $x.ExclusionPath) {
        Remove-MpPreference -ExclusionPath $i
        Write-Host($i)
    }
    Write-Host("================================================")
    Write-Host("Total ExclusionPath entries deleted:", $x.ExclusionPath.Count)
}
else {
    Write-Host("No ExclusionPath entries present. Skipping...")
}

# Get exclusion process
if ($x.ExclusionProcess -ne $NULL) {
    Write-Host("================================================")
    Write-Host("Removing the following ExclusionProcess entries:")
    foreach ($i in $x.ExclusionProcess) {
        Remove-MpPreference -ExclusionProcess $i
        Write-Host($i)
    }
    Write-Host("================================================")
    Write-Host("Total ExclusionProcess entries deleted:", $x.ExclusionProcess.Count)
}
else {
    Write-Host("No ExclusionProcess entries present. Skipping...")
}

# Get exclusion extension
if ($x.ExclusionExtension -ne $NULL) {
    Write-Host("================================================")
    Write-Host("Removing the following ExclusionExtension entries:")
    foreach ($i in $x.ExclusionExtension) {
        Remove-MpPreference -ExclusionExtension $i
        Write-Host($i)
    }
    Write-Host("================================================")
    Write-Host("Total ExclusionExtension entries deleted:", $x.ExclusionExtension.Count)
}
else {
    Write-Host("No ExclusionExtension entries present. Skipping...")
}

# Summary
Write-Host("================================================")
Write-Host("SUMMARY")
Write-Host($x.ExclusionPath.Count, "ExclusionPath entries deleted.")
Write-Host($x.ExclusionProcess.Count, "ExclusionProcess entries deleted.")
Write-Host($x.ExclusionProcess.Count, "ExclusionExtension entries deleted.")
Write-Host(($x.ExclusionPath.Count + $x.ExclusionProcess.Count + $x.ExclusionExtension.Count), "Total entries deleted")
Write-Host("")
Write-Host("Done.")
Stop-Transcript
  • 第 5 行:编辑转录日志路径

运行明确的 Windows Defender 防病毒排除 PowerShell 脚本

要清除 Windows Defender 防病毒排除项:

  1. 以管理员身份运行 PowerShell

  2. 更改 scripts 文件夹的路径

  3. 运行 PowerShell 脚本以删除 Windows Defender 防病毒软件中的所有排除项

  4. 等待 PowerShell 脚本完成

PS C:\> cd c:\scripts
PS C:\scripts> .\Clear-WindowsDefenderExcl.ps1

注意:Windows PowerShell 控制台将显示已删除的排除条目的列表以及包含总计数的摘要。此外,它还会在日志中显示输出,因为脚本已添加到 PS 脚本中。

这是运行 Clear-WindowsDefenderExcl.ps1 PowerShell 脚本后的示例。

[玩转系统] 使用 PowerShell 清除 Windows Defender 防病毒排除项

验证 Windows Defender 防病毒排除项是否已删除

您始终可以在 C:\temp 文件夹中找到日志输出并打开 Clear-WindowsDefenderExcl.txt 文件。

[玩转系统] 使用 PowerShell 清除 Windows Defender 防病毒排除项

验证脚本是否成功删除了 Windows Defender 防病毒软件中的所有排除项。

[玩转系统] 使用 PowerShell 清除 Windows Defender 防病毒排除项

禁用 Windows Defender

假设您想要禁用或卸载 Windows Defender,请阅读以下文章:

  • 永久关闭 Windows 10 中的 Windows Defender

  • 永久关闭 Windows 11 中的 Windows Defender

  • 在 Windows Server 上卸载 Windows Defender

结论

您了解了如何使用 PowerShell 清除 Windows Defender 防病毒排除项。使用 PowerShell 删除所有排除项比在图形用户界面 (GUI) 中手动删除它们要快得多。使用脚本并专注于其他任务。

您喜欢这篇文章吗?您可能还喜欢 Windows 中的安全擦除硬盘驱动器和固态驱动器。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯