Dear all, am looking what property to be used to get vm powered off initiated by and on which date.
get-cluster "*" |get-vm "*"| Select Name, where {$_Powerestate -match "Off"},@{Name="PoweredOff By";Expression={$_.extensionData.property am looking for}} |export-csv .\vmaudit.csv
There is no such property I'm afraid, but you can get that information from the Events.
Provided you keep the Events for a sufficiently long enough time.
Try like this
Get-VIEvent -MaxSamples ([int]::MaxValue) |
where { $_ -is [VMware.Vim.TaskEvent] -and 'VirtualMachine.shutdownGuest', 'VirtualMachine.powerOff' -contains $_.Info.DescriptionId } |
Sort-Object -Property CreatedTime -Descending |
Group-Object -Property { $_.Vm.Name } |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
VM = $_.Name
Date = $_.Group[0].CreatedTime
User = $_.Group[0].UserName
Type = $_.Group[0].Info.Name
})
} | Export-Csv -Path .\vmaudit.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There is no such property I'm afraid, but you can get that information from the Events.
Provided you keep the Events for a sufficiently long enough time.
Try like this
Get-VIEvent -MaxSamples ([int]::MaxValue) |
where { $_ -is [VMware.Vim.TaskEvent] -and 'VirtualMachine.shutdownGuest', 'VirtualMachine.powerOff' -contains $_.Info.DescriptionId } |
Sort-Object -Property CreatedTime -Descending |
Group-Object -Property { $_.Vm.Name } |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
VM = $_.Name
Date = $_.Group[0].CreatedTime
User = $_.Group[0].UserName
Type = $_.Group[0].Info.Name
})
} | Export-Csv -Path .\vmaudit.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i want to add datastore name on which powered off vm is residing VM size along with datastore total size and free size in this script.
Sorry, but I'm going to stop answering your questions.
You keep adding additional requirements.
This makes these threads very long and it makes it difficult for others to search the community for answers.
A better principle would be to start a new thread for a new question.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Noted, will open new thread.
Thank you Master!