Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 180329

poweredoff VM's

$
0
0

Hi,

 

I was unable to generate the poweredoff vm's list with below script. some of the vm's are left unreported. could you please help me

 

$ExportFilePath = "D:\atl.csv"

 

 

$Report = @()

$VMs = get-vm |Where-object {$_.powerstate -eq "poweredoff"}

$Datastores = Get-Datastore | select Name, Id

$VMHosts = Get-VMHost | select Name, Parent

### Get powered off event time:

Get-VIEvent -Entity $VMs -MaxSamples ([int]::MaxValue) |

where {$_ -is [VMware.Vim.VmPoweredOffEvent]} |

Group-Object -Property {$_.Vm.Name} | %{

  $lastPO = $_.Group | Sort-Object -Property CreatedTime -Descending | Select -First 1

  $vm = Get-VIObjectByVIView -MORef $lastPO.VM.VM

  $report += New-Object PSObject -Property @{

    VMName = $vm.Name

    Powerstate = $vm.Powerstate

    OS = $vm.Guest.OSFullName

    IPAddress = $vm.Guest.IPAddress[0]

    ToolsStatus = $VMView.Guest.ToolsStatus

    Host = $vm.host.name

    Cluster = $vm.host.Parent.Name

    Datastore = ($Datastores | where {$_.ID -match (($vmview.Datastore | Select -First 1) | Select Value).Value} | Select Name).Name

    NumCPU = $vm.NumCPU

    MemMb = [Math]::Round(($vm.MemoryMB),2)

    DiskGb = [Math]::Round((($vm.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)

    PowerOFF = $lastPO.CreatedTime

    Note = $vm.Notes  }

}

 

$Report = $Report | Sort-Object VMName

 

if ($Report) {

  $report | Export-Csv $ExportFilePath -NoTypeInformation}

else{

  "No PoweredOff events found"

}


Viewing all articles
Browse latest Browse all 180329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>