I create script to poweroff vms. I would record real-time in a excel or html file which were vms poweroff to follow. Is possible?
I think you would be better examining the Events for obtaining the start and stop times, i.e. the Poweron and Poweroff events.
The following will give you a list of those events over the last 10 days
$events = Get-VIEvent -Start (Get-Date).adddays(-10) |
where {$_ -is [VMware.Vim.VmPoweredOnEvent] -or $_ -is [VMware.Vim.VmPoweredOnEvent]} |
Group-Object -Property {$_.Vm.Name} | %{
$_.Group | Select @{N="VMname"; E={$_.Vm.Name}},
@{N="CreatedTime"; E={$_.CreatedTime}},
@{N='Action';E={if($_ -is [VMware.Vim.VmPoweredOnEvent]){'Poweron'}else{'Poweroff'}}},
@{N="User"; E={$_.UserName}}
}
$events | Export-Csv "C:\VM-power.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Of course, you can use a CSV or HTML file as log.
Have a look at the Export-Csv or ConvertTo-Html cmdlets.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc.
I would like to monitor in real time the exchange status. Example schedule beginning and end of the poweroff . The problem is Export- CSV and converto-html does not change the status after export
Not sure I got the question.
Perhaps include the script, and indicate what you want to capture and where ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Example
Stop-VM -vm $vms -RunAsync -Confirm:$false | select State,PercentComplete,StartTime,FinishTime,ObjectId,Result,Description,Id,Name | ConvertTo-HTML -head $a | Out-File Test.html
But export only StartTime, not possible capture FinishTime in realtime.
I think you would be better examining the Events for obtaining the start and stop times, i.e. the Poweron and Poweroff events.
The following will give you a list of those events over the last 10 days
$events = Get-VIEvent -Start (Get-Date).adddays(-10) |
where {$_ -is [VMware.Vim.VmPoweredOnEvent] -or $_ -is [VMware.Vim.VmPoweredOnEvent]} |
Group-Object -Property {$_.Vm.Name} | %{
$_.Group | Select @{N="VMname"; E={$_.Vm.Name}},
@{N="CreatedTime"; E={$_.CreatedTime}},
@{N='Action';E={if($_ -is [VMware.Vim.VmPoweredOnEvent]){'Poweron'}else{'Poweroff'}}},
@{N="User"; E={$_.UserName}}
}
$events | Export-Csv "C:\VM-power.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc.
Other option is used Excel.Application and export in realtime, but when export stop-vm actions
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
$workbook = $excel.Workbooks.Add()
$sheet = $workbook.ActiveSheet