# follow up script to see verify vmware.log power off times # Modified by Joy Mamer, 2021Nov10 # Main content from LucD https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Collect-stun-time/m-p/527290#M18236 # Issuing power-off request... is guest os shutdown https://kb.vmware.com/s/article/1019064 # CPU reset: hard -> is a power off from vsphere $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' -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 }