PowerShell script to collect all the information for Troubleshooting Windows CH Agent
search cancel

PowerShell script to collect all the information for Troubleshooting Windows CH Agent

book

Article ID: 283977

calendar_today

Updated On: 05-08-2024

Products

CloudHealth

Issue/Introduction

Collecting information from Windows Instances when troubleshooting the Tanzu CloudHealth Agent can be time-consuming. This PowerShell helps speed this process up.

Resolution

The output file will be C:\CHAgentLogs_<date>.zip

# PowerShell script for CloudHealth Agent diagnostic information collection
# Output file: C:\CHAgentLogs_<date>.zip

$logdir = "C:\CHAgentLogs_$((Get-Date).ToString('yyyyMMdd'))"
mkdir $logdir
$log = "$logdir\$((Get-Date).ToString('yyyyMMdd_HHmm')).txt"

Add-Content $log "=============================================================="
Add-Content $log "Agent Version"
Add-Content $log "=============================================================="
Get-WmiObject -Class Win32_Product | Where-Object Name -eq "CloudHealth Agent" | Select-Object Name, Version | Out-File -Append $log
$OS = "$((Get-WMIObject win32_operatingsystem).Caption) $((Get-WmiObject Win32_OperatingSystem).OSArchitecture)"
Add-Content $log $OS
Add-Content $log "=============================================================="
Add-Content $log "Registry Values"
Add-Content $log "=============================================================="
Get-Item 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\CloudHealth Technologies' | Out-File -Append $log
Add-Content $log "=============================================================="
Add-Content $log "Instance ID (For AWS Instance Only, Ignore this for Azure or DC instances)"
Add-Content $log "=============================================================="
Invoke-RestMethod http://169.254.169.254/latest/meta-data/instance-id -ErrorAction SilentlyContinue | Out-File -Append $log
Add-Content $log "=============================================================="
# Enabling TLS 1.2 for the Current PS Session.
$TLS12Protocol = [System.Net.SecurityProtocolType]::Ssl3 -bor [System.Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::SecurityProtocol = $TLS12Protocol
Add-Content $log "CURL CHT API Endpoint"
Add-Content $log "=============================================================="
curl https://api.cloudhealthtech.com/v1/health -UseBasicParsing | Out-File -Append $log
(Get-WmiObject -Class Win32_NTEventlogFile | Where-Object LogfileName -EQ 'CHTAgentEventLog').BackupEventlog("$logdir\CHTAgentEventLog.evtx")

# Create a zip file
Add-Type -Assembly "System.IO.Compression.FileSystem"
[System.IO.Compression.ZipFile]::CreateFromDirectory("$logdir", "$logdir.zip")

List of information collected from the script:

  • Agent version.
  • OS
  • Agent API Key and Proxy Info
  • Instance ID (For AWS Only)
  • Test result to CH API endpoint connection.
  • Agent Event Logs.