VMware ดึงข้อมูล VM ที่มี Snapshot และ Power Off

ติดตั้ง PowerShell 7

  • Update PowerShell
  • winget install –id Microsoft.Powershell –source winget

    Install VMware PowerCLI ด้วย Powershell

    • Install-Module -Name VMware.PowerCLI -Scope CurrentUser
    • Get-Command -Module *VMWare*
    • Set-PowerCLIConfiguration -Scope User -ParticipateInCeip $false

    Trust Root vCenter

    • https://your.vcenter.name/certs/download.zip

    Connect vCenter

    • connect-viserver your.vcenter.name

    Check Snapshot VM

    • Get-VM | Get-Snapshot | select VM, Name, Created | Export-Csv c:\Software\vmsnap1.csv -NoTypeInformation

    Check Power Off VM

    • Get-VM | Where-Object -Property PowerState -eq ‘PoweredOff’ | Select-Object -Property Name, @{Label=’poweredOffTime’; Expression={$_ | Get-VIEvent -Types Info | Where-Object -Property fullformattedmessage -Match ‘shutdown|powered off’ | Sort-Object -Property CreatedTime | Select-Object -Last 1 -ExpandProperty CreatedTime }} | Export-Csv c:\Software\vmoff1.csv -NoTypeInformation