Afternoon. I have a client that has a small but heavily used environment.
2 x clusters with 2 x hosts in each cluster. They have now unable to have a failure as they are consuming too much memory to allow us to perform patching as we can not put a host into maintenance as there are now not enough memory to support 1 host out of the cluster.
I am trying to get a report out that shows the average memory utilisation of each VM over 30 days.
The script is below.
#Editable Varialbles.
$vCenterServerName = "removed"
$User = "removed"
$Password = "removed"
$Export = "removed"
$From = "removed"
$To = "removed"
$Subject = "Average Capacity Report"
$emailbody = "Please find attached the Average Capacity Report"
$SMTPserver = "removed"
#Non-Editable Variables.
$Attachment = $Export
#Virtual Centre Connection.
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer $vCenterServerName -AllLinked -User $User -Password $Password
#Collection Virtual Server Information.
Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Select Name, Host, NumCpu, MemoryMB, `
@{N="CPU Usage (Average), Mhz" ; E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddDays(-30) -IntervalMins 60 | Measure-Object Value -Average).Average),2)}}, `
@{N="Memory Usage (Average), %" ; E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 60 | Measure-Object Value -Average).Average),2)}} , `
@{N="Network Usage (Average), KBps" ; E={[Math]::Round((($_ | Get-Stat -Stat net.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 60 | Measure-Object Value -Average).Average),2)}} , `
@{N="Disk Usage (Average), KBps" ; E={[Math]::Round((($_ | Get-Stat -Stat disk.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 60 | Measure-Object Value -Average).Average),2)}} |`
#Update export file location to be relevant to your network.
Export-Csv $Export
#Send Email Message.
Send-Mailmessage -From $From -To $To -Subject $Subject -Attachments $Attachment $emailbody -Priority Normal -SmtpServer $SMTPServer
Disconnect-VIServer $vCenterServerName -Force -confirm:$false
When the script runs and emails it produces a csv and emails it which is what I am after but the output has columns in it below. I am able to populate all fields except the Host field. What do I need to add to my script to populate the Host field. I thought I could pull it from the Host area when looking at the summary of the VM.
Name | Host | NumCpu | MemoryMB | CPU Usage (Average), Mhz | Memory Usage (Average), % | Network Usage (Average), KBps | Disk Usage (Average), KBps |