The script was attached. I guess I should have mentioned that. Turns out my Row variable didn't work well.
$vmList = Get-Content C:\users\jm\VMware_scripts\SpringCleaning\PoweredOff\all-Nov10.txt # list VMs in txt file
$report = @()
foreach ($vmName in $vmList) {Get-VM -Name $vmName -PipelineVariable vm |
ForEach-Object -Process {
$vmxPath = $vm.ExtensionData.Config.Files.VmpathName
$dsObj = Get-Datastore -Name $vmxPath.Split(']')[0].TrimStart('[')
New-PSDrive -Location $dsObj -Name DS -PSProvider VimDatastore -Root "\" | Out-Null
$tempFile = [System.IO.Path]::GetTempFileName()
Copy-DatastoreItem -Item "DS:\$($vm.Name)\vmware.log" -Destination $tempFile
Get-Content -Path $tempFile | where {($_ -match 'VMX has left the building' -or $_ -match 'CPU reset:')} |
ForEach-Object -Process {
$fields = $_.Split('|')
New-Object -TypeName PSObject -Property @{
VM = $vm.Name
Timestamp = [DateTime]$fields[0]
CPU = $fields[1].Trim(' ')
Duration = $fields[2].Split(' ')[6]
Row = $fields
}
}
Remove-Item -Path $tempFile -Confirm:$false
Remove-PSDrive -Name DS -Confirm:$false
} | Select-Object VM,Timestamp,Duration,Row }