<# Read-only inventory of Hyper-V hosts for Vast Elite AI Copilot. Changes nothing. Run in an elevated PowerShell on a Hyper-V host or a management server with the Hyper-V module, using an account that is a member of "Hyper-V Administrators" (read operations only are used) or a local admin. Pass several hosts or a cluster name. Then send the JSON to Vast: python3 add_customer.py import-onprem --customer "" --file .json Usage: .\collect-hyperv.ps1 -ComputerName hv01,hv02 [-OutFile hyperv.json] or -Cluster HVCLUSTER #> param([string[]]$ComputerName = @($env:COMPUTERNAME), [string]$Cluster, [string]$OutFile = "hyperv-inventory.json") $ErrorActionPreference = 'Stop' if ($Cluster) { $ComputerName = @((Get-ClusterNode -Cluster $Cluster).Name) } $hosts = @(); $vms = @(); $ds = @() foreach ($c in $ComputerName) { $h = Get-VMHost -ComputerName $c $os = (Get-CimInstance -ComputerName $c Win32_OperatingSystem) $list = @(Get-VM -ComputerName $c) $hosts += [pscustomobject]@{ name=$c; version="$($os.Caption) $($os.Version)"; cpu_cores=$h.LogicalProcessorCount; mem_gb=[math]::Round($h.MemoryCapacity/1GB,0); vm_count=$list.Count } foreach ($v in $list) { $disk = 0; try { $disk = [math]::Round((($v.HardDrives | ForEach-Object { (Get-VHD -ComputerName $c -Path $_.Path -ErrorAction SilentlyContinue).Size } | Measure-Object -Sum).Sum)/1GB,0) } catch {} $ip = $null; try { $ip = @($v.NetworkAdapters.IPAddresses | Where-Object { $_ -match '^\d+\.\d+\.\d+\.\d+$' })[0] } catch {} $vms += [pscustomobject]@{ name=$v.Name; state="$($v.State)"; os=""; cpus=$v.ProcessorCount; mem_gb=[math]::Round($v.MemoryAssigned/1GB,1) disk_gb=$disk; host=$c; generation=$v.Generation; ip=$ip } } $ds += Get-CimInstance -ComputerName $c Win32_LogicalDisk -Filter "DriveType=3" | ForEach-Object { [pscustomobject]@{ name="$c $($_.DeviceID)"; type="local"; capacity_gb=[math]::Round($_.Size/1GB,0); free_gb=[math]::Round($_.FreeSpace/1GB,0) } } } $name = if ($Cluster) { $Cluster } else { ($ComputerName -join ",") } $doc = [ordered]@{ type="hyperv"; name=$name; collected_at=(Get-Date).ToUniversalTime().ToString("s")+"Z"; hosts=@($hosts); vms=@($vms); datastores=@($ds); networks=@() } $doc | ConvertTo-Json -Depth 5 | Set-Content -Path $OutFile -Encoding UTF8 Write-Host "Wrote $OutFile : $($vms.Count) VMs on $($hosts.Count) host(s)"