How to add Windows Defender to the file context menu in Windows 8 (PowerShell)

Introduction

This idea is to add Windows defender related cases to context menu so that people can easily scan files or folders in Windows 8.

Scenarios

Sometimes users want to scan files or folder by using Windows Defender manually. But there are several steps to follow. This script is to solve that.

Script

Step 1: Right click the script and select Run with PowerShell.

Step 2: Then it will show UAC message, press YES.

Step 3: After that, it will display a Windows PowerShell console as the following.

Here are some code snippets for your references.

- PowerShell code snippet -
 
$message = "Windows defender exists in context menu, do you want to remove it?"
$result = GetChoice($message)
If($result -eq 0)
{
    Remove-Item  -Path $Scanpath -Force -Confirm:$false -ErrorAction SilentlyContinue
    Remove-Item -Path "$Rootpath1\WindowsDefender" -Recurse -Confirm:$false -Force -ErrorAction SilentlyContinue
    Set-Location -LiteralPath $Rootpath2
    Remove-Item -Path ".\WindowsDefender" -Recurse -Confirm:$false -Force -ErrorAction SilentlyContinue
    Write-Host "Remove 'Scan with Windows Defender' successfully." -ForegroundColor Green
    & cmd /c pause
    exit
}
 
- end -

 

Prerequisite

Windows 8 or later version