I've done something as basic as this:
Get-VM | Export-Csv -path "c:\PowerBI\vminventory.csv" -NoTypeInformation
and more complex like this (see below) - both have multi-hour runtimes - any help would be appreciated!
Function Main
{
Try
{
$vms = Get-VM
$output = foreach($vm in $vms)
{
$vm | select Name,
PowerState,
VmHost,
ProvisionedSpaceGB,
UsedSpaceGB,
NumCpu,
MemoryMB,
Notes,
DNSAddress,
@{N="Up Time (d.hh:mm:ss)";E={[timespan]::FromSeconds((Get-Stat -Entity $vm.Name -Stat sys.uptime.latest -Realtime -MaxSamples 1).Value)}},
@{N='MemAvgPercent';E={$script:stats | where{$_.MetricId -eq 'mem.usage.average'} | Select -ExpandProperty Value}},
@{N='FQDN';E={$vm.ExtensionData.Guest.IPStack[0].DnsConfig.HostName, $vm.ExtensionData.Guest.IPStack[0].DnsConfig.DomainName -join '.'}},
@{Name='ToolsVersion';Expression={$_.Guest.ToolsVersion}},
@{N = "VMNICCount"; E = {$vm.Networkadapters.count}},
@{N="Tools Status";E={$vm.ExtensionData.Guest.ToolsStatus}},
@{N="Configured OS";E={$_.Config.GuestFullName}},
@{N="Running OS";E={$_.Guest.GuestFullName}}
}
$output | Export-Csv -Path "C:\PowerBI\Vmware_Export_Full.csv "
}
catch [Exception]
{
$exception = $_.Exception
Write-Host "Error - $exception" -foreground red
Exit
}
}