VMware Cloud Community
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

VM powered off initiated by

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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-Cluster | Get-VM | where { $_.PowerState -eq 'PoweredOff' } |

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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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-Cluster | Get-VM | where { $_.PowerState -eq 'PoweredOff' } |

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

Reply
0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
VijayKumarMyada
Enthusiast
Enthusiast
Jump to solution

Noted, will open new thread.

Thank you Master!

Reply
0 Kudos