Troubleshooting Hyper-V and Azure Local VMs: Scan Error and Warning Events Across Every Cluster Node with PowerShell

When troubleshooting virtual machine issues on Hyper-V or Azure Local, one of the first places I look is the Windows event logs on the cluster nodes. The challenge, particularly on a clustered platform, is that VM-related events aren’t necessarily recorded on the node currently hosting the virtual machine.

A VM may have migrated between nodes, experienced a storage issue, encountered a virtual switch problem, or triggered an error within the Hyper-V Virtual Machine Management Service (VMMS). Relevant events may be distributed across several Hyper-V event channels and across multiple nodes.

Rather than manually logging into each cluster node, or opening Event Viewer and searching through multiple logs, I have put together a PowerShell script that automates this process.

The script scans Hyper-V event logs across all nodes in an Azure Local or Hyper-V cluster, searching for Error and Warning events associated with a specified VM.

The problem: VM events are spread across multiple cluster nodes

On a standalone Hyper-V host, troubleshooting is relatively straightforward. You can open Event Viewer, navigate to the relevant Hyper-V event logs and filter for events relating to the VM you’re investigating.

On Azure Local, or a traditional Failover Cluster running Hyper-V, things are a little more complicated.

The VM’s current owner node isn’t necessarily the only node containing useful troubleshooting information.

Depending on the issue, relevant events may be found in a number of different Hyper-V event logs, including:

  • Hyper-V-VMMS-Admin – Virtual Machine Management Service events.
  • Hyper-V-VMMS-Operational – Operational events relating to VMMS.
  • Hyper-V-Worker-Admin – Hyper-V worker process events.
  • Hyper-V-Worker-Operational – Worker process operational events.
  • Hyper-V-VMMS-Storage – Storage-related VMMS events.
  • Hyper-V-VMMS-Networking – VMMS networking events.
  • Hyper-V-VmSwitch-Operational – Virtual switch operational events.
  • Hyper-V-Compute-Admin and Hyper-V-Compute-Operational – Compute-related events.

These are just some of the logs that may prove useful when investigating virtual machine issues.

Manually reviewing each of these logs across every node can be time-consuming, particularly when troubleshooting a VM that is experiencing intermittent failures, migration issues, storage problems or unexpected state changes.

Introducing Scan-ClusterVMEvents.ps1

I’ve created a PowerShell script called Scan-ClusterVMEvents.ps1 to simplify this process.

The script allows you to specify a cluster, a virtual machine and the timeframe you want to investigate. It then connects to every node in the cluster and searches a predefined list of Hyper-V event logs for Error and Warning events containing the VM name.

Targeted event search: Searches for Error and Warning events mentioning the specified VM.

Cluster-wide coverage: Connects to all nodes in the cluster, not just the current VM owner.

Parallel execution: Scans nodes concurrently using PowerShell remoting.

CSV export: Exports matching events to a timestamped CSV file.

What the script does

The script follows a straightforward workflow:

  1. Validates the cluster – Confirms the specified cluster can be accessed.
  2. Retrieves cluster nodes – Identifies all nodes participating in the cluster.
  3. Validates the VM – Confirms the virtual machine exists as a clustered VM group.
  4. Calculates the search timeframe – Defaults to the previous 24 hours, but can be extended.
  5. Scans Hyper-V event logs – Searches the selected Hyper-V logs on each cluster node.
  6. Filters events – Returns only Error and Warning events containing the VM name.
  7. Displays and exports results – Displays matching events and saves the output to a CSV file.

The use of Get-WinEvent with -FilterHashtable means the event log query is filtered by log name, start time and event severity before the additional VM-name filtering is applied. This helps reduce the amount of event data returned during the search.

The script also uses Invoke-Command with a throttle limit of five, allowing multiple nodes to be queried concurrently rather than sequentially.

Download and run the script

The script is provided in the code block below:

<#
.SYNOPSIS
    Quickly scans Hyper-V event logs for Errors and Warnings related to a specific virtual machine
    across all nodes of an Azure Local / Azure Stack HCI cluster.

.DESCRIPTION
    This script connects to each node in a specified cluster and searches the Hyper-V event logs 
    for any entries at the Error or Warning level that mention a given VM name. 
    It uses optimized filtering with Get-WinEvent's -FilterHashtable to improve performance,
    and runs parallel scans across cluster nodes using Invoke-Command with a throttle limit.
    The script validates that the cluster exists and that the VM is present before scanning.
    Results are displayed in the console and exported to a timestamped CSV for review.

.PARAMETER ClusterName
    The name of the cluster to scan. Must exist and be reachable from the management server.

.PARAMETER VMName
    The name of the virtual machine to search for. Must exist in the cluster.

.PARAMETER LastHours
    Optional. The number of hours in the past to search for events. Defaults to 24.

.EXAMPLE
    .\Scan-ClusterVMEvents.ps1 -ClusterName "AzHCICluster01" -VMName "MyVM01" -LastHours 48
    Scans the past 48 hours of Hyper-V event logs for Errors and Warnings related to "MyVM01"
    on all nodes in the "AzHCICluster01" cluster.

.EXAMPLE
    .\Scan-ClusterVMEvents.ps1 -ClusterName "azloc-c01" -VMName "arcvm-1"
    Scans the past 24 hours (default) for Errors and Warnings for "arcvm-1" on all nodes 
    in the "azloc-c01" cluster.

.NOTES
    - Requires PowerShell remoting access to all cluster nodes.
    - Requires sufficient permissions to read Hyper-V event logs on each node.
    - Uses a hardcoded list of verified Hyper-V logs to ensure compatibility with Azure Stack HCI nodes.
    - Filters for Error and Warning events using -FilterHashtable to improve performance.
    - Executes node scans in parallel (ThrottleLimit = 5) to speed up execution.
    - Exports results to a CSV file in the current directory with timestamp.
    - Can be extended to include VM GUID-based searching for maximum coverage.
#>

param(
    [Parameter(Mandatory = $true)]
    [string]$ClusterName,

    [Parameter(Mandatory = $true)]
    [string]$VMName,

    [int]$LastHours = 24
)

# Get all Hyper-V related logs
#Get-WinEvent -ListLog *Hyper-V* | Select-Object -ExpandProperty LogName

# Verified Hyper-V logs
$HyperVLogs = @(
    "Microsoft-Windows-Hyper-V-Worker-Operational",
    "Microsoft-Windows-Hyper-V-Worker-Admin",
    "Microsoft-Windows-Hyper-V-VmSwitch-Operational",
    "Microsoft-Windows-Hyper-V-VMSP-Admin",
    "Microsoft-Windows-Hyper-V-VMMS-Storage",
    "Microsoft-Windows-Hyper-V-VMMS-Operational",
    "Microsoft-Windows-Hyper-V-VMMS-Networking",
    "Microsoft-Windows-Hyper-V-VMMS-Admin",
    "Microsoft-Windows-Hyper-V-VID-Admin",
    "Microsoft-Windows-Hyper-V-StorageVSP-Admin",
    "Microsoft-Windows-Hyper-V-Shared-VHDX/Reservation",
    "Microsoft-Windows-Hyper-V-Shared-VHDX/Operational",
    "Microsoft-Windows-Hyper-V-Hypervisor-Operational",
    "Microsoft-Windows-Hyper-V-Hypervisor-Admin",
    "Microsoft-Windows-Hyper-V-High-Availability-Admin",
    "Microsoft-Windows-Hyper-V-Hierarchical-NIC-Switch/Operational",
    "Microsoft-Windows-Hyper-V-Guest-Drivers/Operational",
    "Microsoft-Windows-Hyper-V-Guest-Drivers/Admin",
    "Microsoft-Windows-Hyper-V-Config-Operational",
    "Microsoft-Windows-Hyper-V-Config-Admin",
    "Microsoft-Windows-Hyper-V-Compute-Operational",
    "Microsoft-Windows-Hyper-V-Compute-Admin"
)

$Since = (Get-Date).AddHours(-$LastHours)

Write-Host "=== Hyper-V VM Event Scan ===" -ForegroundColor Cyan
Write-Host "Cluster: $ClusterName"
Write-Host "VM Name: $VMName"
Write-Host "Time Window: Last $LastHours hour(s)`n"

# -------------------------------------------
# Validate cluster exists
# -------------------------------------------
try {
    $Cluster = Get-Cluster -Name $ClusterName -ErrorAction Stop
    Write-Host "✔️ Cluster '$ClusterName' found.`n" -ForegroundColor Green
}
catch {
    Write-Host "❌ ERROR: Cluster '$ClusterName' not found or unreachable." -ForegroundColor Red
    exit 1
}

# Retrieve cluster nodes
try {
    $ClusterNodes = (Get-ClusterNode -Cluster $ClusterName -ErrorAction Stop).Name
    if ($ClusterNodes.Count -eq 0) {
        Write-Host "❌ ERROR: Cluster '$ClusterName' has no nodes." -ForegroundColor Red
        exit 1
    }
}
catch {
    Write-Host "❌ ERROR: Unable to get nodes for cluster '$ClusterName'." -ForegroundColor Red
    exit 1
}

# Validate VM exists
try {
    $ClusterVM = Get-ClusterGroup -Cluster $ClusterName -ErrorAction Stop |
                 Where-Object { $_.GroupType -eq 'VirtualMachine' -and $_.Name -eq $VMName }
    if (-not $ClusterVM) {
        Write-Host "❌ ERROR: VM '$VMName' not found in cluster '$ClusterName'." -ForegroundColor Red
        exit 1
    }
    Write-Host "✔️ VM '$VMName' found.`n" -ForegroundColor Green
}
catch {
    Write-Host "❌ ERROR: Unable to retrieve VM info for '$VMName'." -ForegroundColor Red
    exit 1
}

# -------------------------------------------
# Scan nodes in parallel
# -------------------------------------------
$Results = @()

$ScriptBlock = {
    param($HyperVLogs, $VMName, $Since)

    $Out = @()

    foreach ($Log in $HyperVLogs) {
        try {
            $Filter = @{
                LogName   = $Log
                StartTime = $Since
                Level     = 2,3  # 2=Error, 3=Warning
            }
            $events = Get-WinEvent -FilterHashtable $Filter -ErrorAction Stop |
                      Where-Object { $_.Message -match [regex]::Escape($VMName) }

            foreach ($e in $events) {
                $Out += [PSCustomObject]@{
                    Node        = $env:COMPUTERNAME
                    LogName     = $Log
                    TimeCreated = $e.TimeCreated
                    ID          = $e.Id
                    Level       = $e.LevelDisplayName
                    Message     = $e.Message
                }
            }
        }
        catch {
            # Skip logs that cannot be read
        }
    }

    return $Out
}

# Run Invoke-Command in parallel for speed
$NodeResults = Invoke-Command -ComputerName $ClusterNodes -ScriptBlock $ScriptBlock `
                -ArgumentList $HyperVLogs, $VMName, $Since `
                -ThrottleLimit 5 -ErrorAction SilentlyContinue

if ($NodeResults) {
    $Results += $NodeResults
}

# -------------------------------------------
# Display results
# -------------------------------------------
if ($Results.Count -eq 0) {
    Write-Host "`n✔️ No errors or warnings found for VM '$VMName' in the last $LastHours hour(s)." -ForegroundColor Green
} else {
    Write-Host "`n❗ Events found:" -ForegroundColor Red
    $Results | Format-Table -AutoSize
}

# -------------------------------------------
# Export to CSV
# -------------------------------------------
$OutputFile = ".\${ClusterName}_${VMName}_EventLog_$(Get-Date -Format yyyyMMdd_HHmmss).csv"
$Results | Export-Csv -NoTypeInformation -Path $OutputFile

Write-Host "`n📄 Results exported to: $OutputFile" -ForegroundColor Cyan

Save the script as Scan-ClusterVMEvents.ps1 on a management server or workstation with the Failover Clustering PowerShell tools installed.

Requirements

  • PowerShell remoting must be available and permitted to all cluster nodes.
  • The account running the script must have permissions to read the Hyper-V event logs on each node.
  • The Failover Clustering PowerShell module must be available for cluster and VM validation.
  • The management system must be able to resolve and connect to the cluster nodes.

Running the script

The script accepts three parameters:

ParameterRequiredDescription
ClusterNameYesThe name of the Failover Cluster to scan.
VMNameYesThe clustered VM name to search for.
LastHoursNoThe number of hours to search backwards. Defaults to 24.

Example 1 – Scan the previous 24 hours

The default search window is 24 hours, so you only need to specify the cluster and VM name.

.\Scan-ClusterVMEvents.ps1 -ClusterName "azloc-c01" -VMName "arcvm-1"

This will scan all nodes in azloc-c01 for Error and Warning events mentioning arcvm-1 within the previous 24 hours.

Example 2 – Scan the previous 48 hours

If the issue occurred earlier, you can extend the search timeframe using -LastHours.

.\Scan-ClusterVMEvents.ps1 -ClusterName "AzHCICluster01" -VMName "MyVM01" -LastHours 48

This will search the Hyper-V event logs across all nodes in the cluster for events relating to MyVM01 over the previous 48 hours.

Example 3 – Scan the previous 7 days

For longer-running issues or when investigating an intermittent problem that may have occurred several days ago:

.\Scan-ClusterVMEvents.ps1 -ClusterName "azloc-c01" -VMName "arcvm-1" -LastHours 168

168 hours equates to 7 days.

Understanding the output

If matching events are found, the script displays the results in the PowerShell console and exports them to a CSV file.

The CSV contains the following columns:

ColumnDescription
NodeThe cluster node where the event was recorded.
LogNameThe Hyper-V event log containing the event.
TimeCreatedThe date and time the event was recorded.
IDThe Windows event ID.
LevelThe event severity, such as Error or Warning.
MessageThe event message containing the VM name.

The output file is generated in the current working directory using the cluster name, VM name and timestamp.

For example:

azloc-c01_arcvm-1_EventLog_20261130_081500.csv

This makes it easier to retain troubleshooting data, compare results from different timeframes or share the output with other engineers investigating the issue.

Scan-ClusterVMEvents.ps1

PowerShell script · Ready to save and execute

Download Scan-ClusterVMEvents.ps1

How the script works

1. Cluster validation

The script first attempts to retrieve the cluster using Get-Cluster.

Get-Cluster -Name $ClusterName -ErrorAction Stop

If the cluster cannot be found or accessed, the script displays an error and terminates. This prevents it from proceeding with a scan against an invalid cluster name or inaccessible cluster.

2. Retrieve cluster nodes

Once the cluster has been validated, the script retrieves all cluster nodes:

$ClusterNodes = (Get-ClusterNode -Cluster $ClusterName -ErrorAction Stop).Name

This is important because the script doesn’t rely on the VM’s current owner node. Instead, it collects the node names from the cluster and uses these as the targets for the remote event log queries.

3. Validate the VM

The script uses Get-ClusterGroup to retrieve clustered VM groups and validate that the specified VM exists.

$ClusterVM = Get-ClusterGroup -Cluster $ClusterName |
    Where-Object {
        $_.GroupType -eq 'VirtualMachine' -and
        $_.Name -eq $VMName
    }

This ensures that the name supplied to the script corresponds to a clustered virtual machine.

4. Search Hyper-V event logs

The core of the script is the remote PowerShell script block that executes against each cluster node.

For each log in the predefined list, it builds a filter using Get-WinEvent:

$Filter = @{
    LogName   = $Log
    StartTime = $Since
    Level     = 2,3
}

Event severity filtering

Level 2

Error

Level 3

Warning

This limits the initial event query to Error and Warning events recorded since the specified start time.

The results are then filtered further using the VM name:

Where-Object { $_.Message -match [regex]::Escape($VMName) }

Using [regex]::Escape() ensures the VM name is treated as a literal string rather than a regular expression pattern.

When a matching event is found, the script extracts the node name, event log, timestamp, event ID, severity and event message.

5. Execute scans concurrently

Rather than connecting to each node individually and waiting for each scan to finish, the script uses PowerShell remoting:

$NodeResults = Invoke-Command -ComputerName $ClusterNodes `
    -ScriptBlock $ScriptBlock `
    -ArgumentList $HyperVLogs, $VMName, $Since `
    -ThrottleLimit 5 -ErrorAction SilentlyContinue

The -ThrottleLimit 5 parameter allows up to five concurrent remote connections, making the script particularly useful for larger clusters where sequential log searches would take longer.

6. Export the results

Finally, the script displays the results and exports them to a CSV file.

The CSV can then be opened in Excel, filtered by node, event ID, log name or timestamp, and used to correlate events during troubleshooting.

Important considerations

Whilst this script is designed to provide a quick overview of VM-related Hyper-V events, there are a few limitations worth understanding.

  • Event message matching: The script searches the event message for the VM name. Events that reference only a VM GUID or another identifier may not be captured.
  • Log availability: Some Hyper-V logs may not exist, be enabled or be accessible on a particular node. The script skips logs that generate errors during the query.
  • Permissions: PowerShell remoting and event log access permissions must be in place across all nodes.
  • Event coverage: The script searches a predefined list of Hyper-V logs, so it isn’t intended to replace a comprehensive investigation of all Windows event logs.
  • Search timeframe: The timeframe is based on the local system time of the management server running the script.

For more comprehensive troubleshooting, the script could be extended to search using the VM’s GUID, include additional Windows event logs, or capture events that don’t contain the VM name directly in the event message.

Example screen shot:

Conclusion

When troubleshooting virtual machine issues on Azure Local or Hyper-V, having a quick way to gather relevant events across every cluster node can save considerable time.

Instead of manually checking multiple nodes and event logs, Scan-ClusterVMEvents.ps1 provides a simple way to collect Error and Warning events associated with a specific VM within a defined timeframe.

It isn’t intended to replace detailed troubleshooting, but it provides a useful starting point when investigating VM failures, unexpected state changes, storage or networking issues, and other Hyper-V problems.

I hope you find this useful, and as always, feedback and suggestions for improvements are welcome.

Post Disclaimer

The information contained in the posts in this blog site is for general information purposes only. The information in this post "Troubleshooting Hyper-V and Azure Local VMs: Scan Error and Warning Events Across Every Cluster Node with PowerShell" is provided by "Lee Harrison's Technical Blog" and whilst we endeavour to keep the information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services, or related graphics contained on the post for any purpose. Furthermore, it is always recommended that you test any related changes to your environments on non-production systems and always have a robust backup strategy in place.

Leave a Reply

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