From 24a882090465c31f7807ed83f4d1a274a18ba6f6 Mon Sep 17 00:00:00 2001 From: Belim Date: Mon, 8 Sep 2025 21:06:43 +0200 Subject: [PATCH] Add files via upload --- .../Microsoft Defender maintenance.ps1 | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 Flyoobe.Extensions/Microsoft Defender maintenance.ps1 diff --git a/Flyoobe.Extensions/Microsoft Defender maintenance.ps1 b/Flyoobe.Extensions/Microsoft Defender maintenance.ps1 new file mode 100644 index 0000000..1d0e4ba --- /dev/null +++ b/Flyoobe.Extensions/Microsoft Defender maintenance.ps1 @@ -0,0 +1,102 @@ +# Microsoft Defender maintenance (update signatures, repair, show status) +# Host: console +# Options: Update signatures; Repair definitions and update; Show Defender status + +param([string]$choice) + +function Get-MpCmdPath { + $candidates = @( + "$env:ProgramFiles\Windows Defender\MpCmdRun.exe", + "$env:ProgramFiles\Microsoft Defender\MpCmdRun.exe" + ) + foreach ($p in $candidates) { if (Test-Path $p) { return $p } } + return $null +} + +function Is-Admin { + $id = [Security.Principal.WindowsIdentity]::GetCurrent() + $pr = New-Object Security.Principal.WindowsPrincipal($id) + return $pr.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +} + +function Show-Status { + try { + $s = Get-MpComputerStatus + Write-Output "=== Microsoft Defender Status ===" + Write-Output ("Engine version: {0}" -f $s.AMEngineVersion) + Write-Output ("Platform version: {0}" -f $s.AMProductVersion) + Write-Output ("AV signature version: {0}" -f $s.AntivirusSignatureVersion) + Write-Output ("AV signature last update: {0}" -f $s.AntivirusSignatureLastUpdated) + Write-Output ("AS signature version: {0}" -f $s.AntispywareSignatureVersion) + Write-Output ("Real-time protection: {0}" -f $s.RealTimeProtectionEnabled) + Write-Output ("NIS enabled: {0}" -f $s.NISEnabled) + Write-Output ("Service enabled: {0}" -f $s.AMServiceEnabled) + } catch { + Write-Output "✘ Failed to read Defender status: $($_.Exception.Message)" + } +} + +switch ($choice) { + + "Update signatures" { + if (-not (Is-Admin)) { + Write-Output "ℹ Tip: Run as Administrator for the most reliable results." + } + + try { + # Primary: PowerShell cmdlet + Update-MpSignature -ErrorAction Stop + Write-Output "✔ Signatures updated via Update-MpSignature." + } catch { + # Fallback: MpCmdRun + $mp = Get-MpCmdPath + if ($mp) { + Write-Output "↻ Falling back to MpCmdRun.exe ..." + & $mp -SignatureUpdate | Out-String | Write-Output + } else { + Write-Output "✘ MpCmdRun.exe not found and Update-MpSignature failed." + } + } + + Show-Status + } + + "Repair definitions and update" { + if (-not (Is-Admin)) { + Write-Output "✘ Please run this action as Administrator (required to reset definitions)." + break + } + + $mp = Get-MpCmdPath + if (-not $mp) { + Write-Output "✘ MpCmdRun.exe not found." + break + } + + try { + Write-Output "↻ Removing all definitions (repair) ..." + & $mp -RemoveDefinitions -All | Out-String | Write-Output + } catch { + Write-Output "✘ Failed to remove definitions: $($_.Exception.Message)" + } + + try { + Write-Output "↻ Updating signatures ..." + Update-MpSignature -ErrorAction Stop + Write-Output "✔ Signatures updated." + } catch { + Write-Output "↻ Fallback: MpCmdRun signature update ..." + & $mp -SignatureUpdate | Out-String | Write-Output + } + + Show-Status + } + + "Show Defender status" { + Show-Status + } + + default { + Write-Output "✘ Unknown option: $choice" + } +}