T O P

Powershell One-liner to Check Log Files

Troubleshooting Windows Update with a Little PowerShell Magic

Let’s suppose you’ve just joined a computer to a WSUS server, but Windows Update has decided it doesn’t feel like downloading patches today.

Naturally, your first instinct is to check the logs. But who wants to spend their afternoon digging through files looking for an error?

Fortunately, PowerShell can do the dirty work for us.

Back in the day, Windows Update maintained a nice, readable log file. Finding warnings was as simple as:

Get-ChildItem C:\Windows -Filter '*update*.log' -File -Recurse -ErrorAction SilentlyContinue |
    Select-String 'warning'

One line, and PowerShell searches for matching log files, reads their contents, and displays anything containing the word “warning.”

In my case, the result was rather revealing:

WARNING: Failed to find updates with error code 800B0001
WARNING: Digital Signatures are not trusted: Error 0x800b0001
WARNING: SelfUpdate check failed, error = 0x800B0001
WARNING: Skipping scan, self-update check returned 0x800B0001

Aha! There’s our culprit: 0x800B0001, pointing toward a digital signature verification issue.

But wait, it’s not 2013 anymore!

Modern Windows versions (Windows 10, Windows 11, and newer Windows Server releases) no longer maintain the same continuously updated text log. Instead, they use Event Tracing for Windows (ETW).

Not quite as convenient, but PowerShell still has our backs.

First, generate a readable log:

Get-WindowsUpdateLog -LogPath "$env:TEMP\WindowsUpdate.log"

Then search it:

Select-String "$env:TEMP\WindowsUpdate.log" -Pattern 'warning','error','failed'

Or, if you’re feeling particularly efficient, skip the log file altogether and query the Windows Update event log:

Get-WinEvent -FilterHashtable @{
    LogName = 'Microsoft-Windows-WindowsUpdateClient/Operational'
    Level = 2,3
} -MaxEvents 20 | Select-Object TimeCreated, Message

That retrieves up to 20 recent error and warning events, without opening Event Viewer.

And yes, these approaches work with Windows PowerShell 5.1 and modern PowerShell 7 versions.

One last trick

For traditional text logs that are actively being written, you can still watch for errors in real time:

Get-Content C:\Logs\Application.log -Tail 20 -Wait |
    Select-String 'warning','error'

Just remember that this trick doesn’t work directly with modern Windows Update’s binary ETW traces.

The moral of the story?

Windows Update may have changed how it keeps its secrets, but PowerShell is still remarkably good at getting them out.

Happy troubleshooting!

Finding Windows Services That Are Stopped That Should Be Started With Powershell

This was a scriptlet that got heavy use on servers and even in our RMM. It can report back services on Windows servers and desktops are are in the Stopped state that are set to Auto or Enabled.

GWMI is short for Get-WmiObject

GWMI win32_service -Filter "startmode = 'auto' AND state != 'running'"  | select DisplayName, Name, StartMode, State, ExitCode | ft -auto

Get VM Snapshots via Powershell

This is a little script / scriptlet I came up with when working at my old MSP. We unfortunately had employees who had the tendency to create snapshots in Windows Server and Hyper-V and then leave them. For long periods of time. As in months and even a year plus. These snapshots would grow and of course be a pain in the butt to merge and get rid of.

I ran this in our RMM tool and was able to set an alert or report to it. If there are no snapshots, it exits successfully (Exit 0). If there are snapshots, it says how many there are and exists with a code 1001. You can then have your RMM or log checker alert on that code.

$results=get-vmsnapshot -vmname * | Select VMName, Name, CreationTime
$count=$results | measure | Select Count
If ($count.Count -eq 0) 
	{Write-Host "No snapshots found"
	Exit 0}
Else {Write-Host $results.VMName 'has' $count.Count 'snapshots'
Exit 1001}

Deleting Folders or Files

I recently ran into an error with a client’s off-site backup using Cloudberry to Backblaze B2 that simply said: file name segment must be no more than 250 bytes

Nice, right? Digging into the logs, I found that it was erroring out on an amazingly long .JS file a user had copied over with a bunch of personal files.

Enter SuperDelete on Github. Download it from the release page or compile it yourself, move it to the problem folder and let it do its magic. Simply run the executable (no installation necessary!) and name the file in question and you’re golden!