7 PowerShell Commands to Check a Hacked Windows PC

  • Windows
  • PowerShell
  • Security
  • 10 min read
7 PowerShell Commands to Check a Hacked Windows PC

If you think a hacked Windows PC is in front of you, these 7 PowerShell commands show what is running on it, what it has been talking to, and what changed. They are built into Windows, so there is nothing to download, and they only read information.

Last updated: November 2026

In short

  • All 7 commands work in Windows PowerShell 5.1 and PowerShell 7 on Windows 10 and Windows 11.
  • None of them changes or deletes anything. They are safe to run while you decide what to do next.
  • Run PowerShell as administrator. Without it, some commands show only half the picture, and the Security log stays closed.
  • Save what you find before you clean anything. The evidence is easy to lose.

First, cut it off from the network

If you are fairly sure the PC is compromised, unplug the network cable or turn off Wi-Fi before you start. That stops an attacker from watching you, and stops the PC from spreading anything. Do not restart or shut it down yet: a restart clears the DNS cache and the list of running programs, which are two of the things you want to see. On a work PC, call your IT or security team first and follow their process.

How to Open PowerShell as Administrator

Right-click the Start button and choose Terminal (Admin) on Windows 11, or Windows PowerShell (Admin) on Windows 10. Click Yes when Windows asks for permission. The window title should start with “Administrator”.

Run these commands only on computers you own or are responsible for. Microsoft lists every option of each command in the PowerShell reference.

The 7 Commands for a Hacked Windows PC at a Glance

PS C:\> incident-check

  1. Get-CimInstance Win32_ProcessEvery program running, and the command that started it
  2. Get-DnsClientCacheWebsites and servers this PC looked up recently
  3. Get-CimInstance Win32_ServiceThe program behind every service
  4. Get-WinEvent ... Id=4720Every user account created
  5. Get-PSReadLineOptionCommands typed in PowerShell
  6. Get-MpThreatDetectionThreats Microsoft Defender found
  7. Get-FileHashA file’s SHA256 fingerprint, ready to look up

Tap a command to jump to it. “admin” = this one needs PowerShell as administrator.

What Is Running Right Now?

01 Get-CimInstance Win32_Process: Every Process and Its Command Line

  • Read-only
  • Admin to see every process

Task Manager shows the names of running programs. This command also shows the full command that started each one, which is where most attacks give themselves away. A program called svchost.exe looks normal; a powershell.exe started with a long scrambled argument does not.

powershell
Get-CimInstance Win32_Process | Select-Object Name, ProcessId, ParentProcessId, CommandLine
powershell
Get-CimInstance Win32_Process | Where-Object CommandLine -match '\\Temp\\|\\Users\\Public\\| -enc | -EncodedCommand ' | Select-Object Name, ProcessId, CommandLine

The second command shows only processes that run from a Temp folder or the Public folder, or that use an encoded PowerShell command. On a clean PC it usually finds nothing or almost nothing. Things worth a closer look:

  • powershell.exe with -enc or -EncodedCommand followed by a long block of letters. Attackers encode commands so you cannot read them at a glance.
  • Programs running from a Temp folder or C:\Users\Public. Many normal apps, such as Teams, Zoom and VS Code, run from AppData, so check the names you do not know there instead of everything.
  • Windows tools used in odd ways, such as mshta.exe, rundll32.exe or certutil.exe with a web address in the command line.

ParentProcessId tells you which process started each one. Microsoft Word starting PowerShell, for example, is a common sign of a booby-trapped document.

Run it as administrator

In a normal window, CommandLine is empty for processes that belong to other accounts or to Windows. On our test PC, a normal window showed the command line for only about half of the processes.

02 Get-DnsClientCache: Domains This PC Looked Up

  • Read-only

Before a PC connects to a website or a server, it looks up the name in DNS and keeps the answer for a while. This command lists those saved answers, so you can see which names the PC has been reaching recently, including names that malware called home to.

powershell
Get-DnsClientCache | Select-Object Entry, Data
powershell
Get-DnsClientCache | Sort-Object Entry -Unique | Select-Object -ExpandProperty Entry

Look for names you do not recognize, random-looking names such as x7f3kq9a.example.top, and names that copy a real brand with one letter changed. Each entry only stays in the cache for as long as its DNS record allows, often minutes, and the cache is cleared at every restart. That is why you run this one early.

An empty list is not proof that nothing happened. A VPN or a security app that handles DNS itself can keep the Windows cache empty. Our DNS troubleshooting guide explains how lookups and caching work.

03 Get-CimInstance Win32_Service: The Program Behind Every Service

  • Read-only

A service starts with Windows and runs in the background, even when nobody is logged in. That makes it a favorite place for malware to hide. This command shows the program file each service runs.

powershell
Get-CimInstance Win32_Service | Select-Object Name, State, StartMode, PathName
powershell
Get-CimInstance Win32_Service | Where-Object { $_.PathName -and $_.PathName -notmatch 'C:\\Windows\\' } | Select-Object Name, State, PathName

The second command hides the services that run from the Windows folder, which leaves the ones installed by other software. On a normal PC that is still a few dozen, mostly drivers and updaters from companies you know. Look for:

  • A program in AppData, Temp, C:\Users\Public or C:\ProgramData with a random name.
  • A copy of a Windows program name, such as svchost.exe, running from anywhere other than C:\Windows\System32.
  • A service name that sounds official but has no company behind it when you search for it.

Services are not the only way to start with Windows. Two more places are worth one look each:

powershell
Get-CimInstance Win32_StartupCommand | Select-Object Name, Command, Location
powershell
Get-ScheduledTask | Where-Object State -ne 'Disabled' | Select-Object TaskName, TaskPath

What Changed on the PC?

04 Get-WinEvent: Every User Account Created

  • Admin prompt
  • Read-only

Attackers often create their own account so they can come back later. Windows writes event 4720 to the Security log each time a user account is created. This command lists those events.

powershell (admin)
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4720} | Format-List TimeCreated, Message
powershell (admin)
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4732} | Format-List TimeCreated, Message

The second command shows event 4732: an account added to a local group. When the group is Administrators, someone gave an account full control of the PC. For each event, compare the time with when the trouble started, and check that you know the account.

  • “No events were found that match the specified selection criteria” is a normal answer. It means no account was created while the log kept records.
  • The Security log has a size limit, so old events are overwritten. On a busy PC it may only reach back a few days.
  • To see the current list of local accounts, run Get-LocalUser. To see who is an administrator, run Get-LocalGroupMember Administrators.

05 Get-PSReadLineOption: Commands Typed in PowerShell

  • Read-only

PowerShell saves every command a user types into a text file in their profile. If an attacker used PowerShell by hand, their commands may still be there.

powershell
Get-Content (Get-PSReadLineOption).HistorySavePath
powershell
Get-ChildItem 'C:\Users\*\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt'

The first command shows your own history. The file is ConsoleHost_history.txt in your AppData\Roaming folder. The second command, run as administrator, finds the same file for every user on the PC, so you can open each one with Get-Content.

Look for downloads (Invoke-WebRequest, iwr, curl), commands that turn off Defender (Set-MpPreference), and new users or passwords (net user, New-LocalUser).

What the history does not show

It only records commands typed into a PowerShell window. Scripts that ran on their own are not in it, and a careful attacker can delete the file. An empty history proves nothing; a suspicious one tells you a lot.

06 Get-MpThreatDetection: Threats Microsoft Defender Found

  • Read-only
  • Admin for exclusions

Microsoft Defender keeps a history of what it caught, including threats it already removed. This command lists that history: the threat, the file it was in, and when it was found.

powershell
Get-MpThreatDetection
powershell
Get-MpComputerStatus | Select-Object AntivirusEnabled, RealTimeProtectionEnabled, AntivirusSignatureLastUpdated
powershell
Get-MpPreference | Select-Object ExclusionPath, ExclusionProcess, ExclusionExtension
  • The second command checks that Defender is on and up to date. Attackers often turn real-time protection off.
  • The third command, run as administrator, shows folders and programs Defender has been told to skip. An exclusion you did not add, such as a folder in AppData, is a strong warning sign.
  • If the PC uses a different antivirus, Defender stays in the background and these commands report nothing. Check that antivirus program’s own history instead.

Check a Suspicious File

07 Get-FileHash: A File’s SHA256 Fingerprint

  • Read-only

A hash is a fingerprint of a file. If even one byte changes, the hash changes. Get-FileHash uses SHA256 by default and prints a 64-character code.

powershell
Get-FileHash .\suspect.exe
powershell
Get-FileHash 'C:\Users\Public\update.exe' | Select-Object -ExpandProperty Hash

Paste the hash into the search box on VirusTotal. If many antivirus engines already know the file, you will see their results at once. Searching by hash does not upload the file, so it is safe for private files.

If VirusTotal has never seen the hash, that does not mean the file is clean. New malware is often unique to one attack. Keep the file and its hash for your notes.

Save Everything Before You Clean Up

Once you start removing things, the evidence is gone. These commands save the results of the commands above into one folder. Run them in PowerShell as administrator, then copy the folder to a USB stick.

powershell (admin)
New-Item -ItemType Directory -Path C:\IR -Force
powershell (admin)
Get-CimInstance Win32_Process | Select-Object Name, ProcessId, ParentProcessId, CommandLine | Export-Csv C:\IR\processes.csv -NoTypeInformation
powershell (admin)
Get-DnsClientCache | Export-Csv C:\IR\dns-cache.csv -NoTypeInformation
powershell (admin)
Get-CimInstance Win32_Service | Select-Object Name, State, StartMode, PathName | Export-Csv C:\IR\services.csv -NoTypeInformation
powershell (admin)
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4720,4732} -ErrorAction SilentlyContinue | Select-Object TimeCreated, Id, Message | Export-Csv C:\IR\account-events.csv -NoTypeInformation
powershell (admin)
Get-MpThreatDetection | Export-Csv C:\IR\defender.csv -NoTypeInformation

What to Do If You Find Something

  1. Keep the PC off the network, and save the results as shown above.

  2. From a different, clean device, change the passwords for email, banking and any account used on that PC. Turn on two-step sign-in where you can.

  3. Run a Microsoft Defender Offline scan from Windows Security, under Virus & threat protection, Scan options. It restarts the PC and scans before Windows loads, which catches malware that hides while Windows is running.

  4. If the attacker had administrator rights, the safest fix is to back up your personal files and reinstall Windows. Cleaning by hand can miss something.

  5. On a work PC, hand everything to your IT or security team and let them decide.

Frequently Asked Questions

Can these commands remove a virus?

No. They only show information. Use Microsoft Defender or your antivirus to remove threats, and reinstall Windows if the attacker had administrator rights.

Do they work in the old Windows PowerShell and in PowerShell 7?

Yes. All 7 are part of Windows PowerShell 5.1, which comes with Windows 10 and 11, and they also run in PowerShell 7 on Windows.

Why do I get “Access is denied” or empty results?

Open PowerShell as administrator. The Security log, other users’ command lines and Defender exclusions are hidden from normal windows.

Is it safe to upload a suspicious file to VirusTotal?

Searching for its hash is always safe. Uploading the file shares it with security companies, so do not upload documents that contain private or company data.

Key Takeaways

  • Disconnect a hacked Windows PC from the network, but do not restart it until you have looked.
  • Run PowerShell as administrator, or several commands only show part of the picture.
  • Command lines, services and new accounts are where most attackers leave traces.
  • Save the results to a folder before you remove anything.
  • A clean result is not proof. When in doubt, back up your files and reinstall Windows.

Related guides on infotechtu.com

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top