vmCalgary
Enthusiast
Enthusiast

I'm going to let Excel do some heavy lifting. I'll use out-file and send to txt. Then copy and paste into excel and use the 'convert text to columns' feature.

2021-11-10_15-22-51.jpg

Final code (for now):

 

$vmList = Get-Content C:\users\jmamer\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|CPU reset:|power|Power|vmotion|Vmotion' } |

    ForEach-Object -Process {

 $fields = $_.Split('|')

    New-Object -TypeName PSObject -Property @{

     VM = $vm.Name

     Timestamp = [DateTime]$fields[0]
          
     Row = $fields

        }

    }

    Remove-Item -Path $tempFile -Confirm:$false

    Remove-PSDrive -Name DS -Confirm:$false

 } |  Select-Object VM,Timestamp,Row }

 

I'll run a function in Excel to see which VMs are missing (no vmware.log).

It could be prettier but I need to get to the analysis part of the problem I'm working on with reclaiming resources. Thanks so much Luc.

View solution in original post

Reply
0 Kudos