![[Image: Ao15uxN.gif]](https://imgur.com/Ao15uxN.gif)
⚡ PowerShell Scripting for Malware Removal ⚡
PowerShell is a powerful scripting tool that can help remove malware, analyze system infections, and harden security settings. This guide will teach you how to use PowerShell for malware detection and removal.
![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
🔍 Step 1: Run PowerShell as Administrator
To execute scripts with full system access:
1️⃣ Press Win + X, then select Windows Terminal (Admin) or PowerShell (Admin).
2️⃣ If prompted by User Account Control (UAC), click Yes.
To check the PowerShell version, run:
Code
$PSVersionTable.PSVersionEnsure you are using PowerShell 5.1 or later for maximum compatibility.
![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
⚠️ Step 2: Enable Execution of Scripts (If Blocked)
By default, PowerShell restricts script execution. To enable it, run:
Code
Set-ExecutionPolicy Unrestricted -Scope CurrentUserTo allow signed scripts only (more secure):
Code
Set-ExecutionPolicy RemoteSignedTo check the current policy:
Code
Get-ExecutionPolicy![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
🦠 Step 3: Detect and Terminate Malicious Processes
Run the following command to list suspicious processes:
Code
Get-Process | Sort-Object CPU -Descending | Select-Object -First 20To kill a process by name:
Code
Stop-Process -Name "maliciousprocess" -ForceTo kill a process by Process ID (PID):
Code
Stop-Process -Id 1234 -ForceUse this to scan for unknown or high-CPU usage processes and terminate them.
![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
📂 Step 4: Identify and Remove Suspicious Startup Items
Malware often persists by adding itself to startup locations. Run:
Code
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"To remove a suspicious startup entry:
Code
Remove-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "MalwareName" -ForceAlso check for scheduled tasks:
Code
Get-ScheduledTask | Where-Object {$_.TaskPath -like "*Malware*" }To delete a suspicious task:
Code
Unregister-ScheduledTask -TaskName "MalwareTask" -Confirm:$false![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
🛡 Step 5: Scan for Malware Files
To find suspicious files in common malware locations, run:
Code
Get-ChildItem -Path "C:\Users\*\AppData\Local\Temp","C:\ProgramData" -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Extension -in ".exe", ".bat", ".vbs", ".js", ".cmd" } |
Select-Object FullName, LastWriteTime | Format-Table -AutoSizeTo delete a suspicious file:
Code
Remove-Item -Path "C:\Path\To\Malware.exe" -Force -ErrorAction SilentlyContinueTo delete all executables in Temp folders:
Code
Remove-Item -Path "C:\Users\*\AppData\Local\Temp\*.exe" -Force -ErrorAction SilentlyContinue![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
🛠 Step 6: Reset Network & Firewall Settings (Fix Hijacked Settings)
If malware has modified your proxy settings, reset them:
Code
netsh winhttp reset proxyTo reset the DNS settings:
Code
Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter | Select-Object -First 1).InterfaceIndex -ResetServerAddressesTo reset Windows Firewall rules:
Code
netsh advfirewall reset![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
🔍 Step 7: Check & Remove Rogue Services
List non-Microsoft services:
Code
Get-Service | Where-Object { $_.StartType -eq "Auto" -and $_.Status -eq "Running" -and $_.Name -notmatch "Microsoft|Windows" } |
Select-Object Name,DisplayName | Format-Table -AutoSizeTo stop and delete a suspicious service:
Code
Stop-Service -Name "MalwareService" -Force
sc.exe delete MalwareService![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
🚀 Step 8: Run Windows Defender Quick Scan
Use Windows Defender's built-in PowerShell commands for scanning:
Code
Start-MpScan -ScanType QuickScanFor a full scan:
Code
Start-MpScan -ScanType FullScanTo update Defender before scanning:
Code
Update-MpSignature![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
🔄 Step 9: Restore System Integrity (Fix Corrupt Files)
If malware has corrupted system files, run:
Code
sfc /scannowFor deeper corruption issues, use:
Code
DISM /Online /Cleanup-Image /RestoreHealth![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
💡 Step 10: Hardening Your System Against Malware
After removing malware, take these steps to prevent future infections:
✅ Enable Controlled Folder Access (prevents ransomware):
Code
Set-MpPreference -EnableControlledFolderAccess Enabled✅ Block unsigned scripts from running:
Code
Set-ExecutionPolicy AllSigned✅ Disable automatic execution of removable media:
Code
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" -Name NoDriveTypeAutoRun -Value 255 -Force✅ Enable Windows Defender's real-time protection:
Code
Set-MpPreference -DisableRealtimeMonitoring 0![[Image: h9AAT39.gif]](https://imgur.com/h9AAT39.gif)
🎯 Conclusion
PowerShell is a powerful tool for malware detection and removal. This guide provides commands to help you:
✔️ Kill suspicious processes
✔️ Remove malware from startup
✔️ Scan and delete malicious files
✔️ Reset network & firewall settings
✔️ Check & remove rogue services
✔️ Run Defender scans and restore system integrity
For further analysis, consider uploading suspicious files to VirusTotal:
📌 VirusTotal Online Scanner
⚠️ Always verify commands before running them. Misuse of PowerShell can harm your system.

