Monitoring and Health Reporting with PowerCLI: VMs, Hosts, Snapshots, and Orphaned Objects

Introduction

Proactive monitoring is key to reducing incidents and downtime. PowerCLI makes it easy to schedule and automate health checks, track configuration drift, and alert on silent risks such as orphaned snapshots or VMs.

In this article, you will learn how to:

  • Generate daily health summaries
  • Audit snapshots and VM tools status
  • Identify disconnected or orphaned VMs
  • Track configuration anomalies
  • Export and schedule automated reports

My Personal Repository on GitHub

VMware Repository on GitHub


Health Check Report: Overview

Start by collecting data across core inventory components:

$report = @()

Get-VM | ForEach-Object {
$report += [PSCustomObject]@{
Name = $_.Name
PowerState = $_.PowerState
VMTools = $_.ExtensionData.Guest.ToolsStatus
Host = $_.VMHost.Name
SnapshotAge = ($_ | Get-Snapshot | Sort-Object Created -Descending | Select-Object -First 1).Created
}
}

$report | Export-Csv "C:\Reports\VM_HealthReport.csv" -NoTypeInformation

Snapshot Auditing

Find VMs with Snapshots Older Than 7 Days

Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-7)} | Select VM, Name, Created

Remove All Snapshots Older Than 14 Days

Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-14)} | Remove-Snapshot -Confirm:$false

Identify Disconnected or Invalid VMs

Orphaned VMs

Get-VM | Where-Object {$_.PowerState -eq "Unknown"}

VMs with Invalid or Missing Files

Get-VM | Where-Object {$_.ExtensionData.Summary.Runtime.ConnectionState -eq "invalid"}

Diagram: Report Automation Flow


Scheduled Daily Report Script

Save this script and use Task Scheduler or cron to run it each morning.

$report = Get-VM | Select Name, PowerState, @{N="ToolsStatus";E={$_.ExtensionData.Guest.ToolsStatus}}, @{N="SnapshotCount";E={($_ | Get-Snapshot).Count}}, VMHost

$timestamp = Get-Date -Format "yyyy-MM-dd"
$report | Export-Csv -Path "C:\Reports\Daily_VM_Report_$timestamp.csv" -NoTypeInformation

Use Case: Compliance Snapshot Audit Before Change Windows

Before patching or upgrades, ensure that:

  • VMs do not have old snapshots
  • VMware Tools are up to date
  • VMs are powered on and reachable

Use this PowerCLI one-liner:

Get-VM | Where-Object {
($_.PowerState -eq "PoweredOn") -and
(($_ | Get-Snapshot).Count -eq 0) -and
($_.ExtensionData.Guest.ToolsStatus -eq "toolsOk")
}

Add-on: HTML Reporting (Optional)

Convert reports to HTML for email or dashboard use.

$report = Get-VM | Select Name, PowerState, VMHost
$report | ConvertTo-Html -Title "VM Summary Report" | Out-File "C:\Reports\VM_Summary.html"

Troubleshooting Report Failures

IssueFix
Snapshot command fails on some VMsCheck for permissions or backup locks
ToolsStatus returns blankEnsure VM is powered on and Tools are installed
PowerCLI script does not export fileConfirm write permissions and file path exists
Email or automation integration failsUse PowerShell Send-MailMessage with proper SMTP credentials

What’s Next

In the next article, we will explore:

  • Custom PowerCLI workflows for tag-driven automation
  • Health checks and remediation logic based on tag metadata

Leave a Reply

Discover more from Digital Thought Disruption

Subscribe now to keep reading and get access to the full archive.

Continue reading