I want to get a vCenter Report for all VM with all possible fields on email from a powercli script. I don't have any script, I normally fetch report from RV tools, but it's giving me lot's of unnecessary fields.
If i can get mutiple vCenter report on single email, that would be really good.
I appreciate if I get a script.
Thanks in advance!
----------------
Update Message:
below script can work for me (copied from one post) but need to add some fields like CpuUsage (Mhz), MemoryUsage (GB), Provisioned Space, Used Space, HA Protection, Consolidation status, VM ID and need it on email in excel or csv format.
$report = @()
foreach($vm in Get-View -ViewType Virtualmachine){
$vms = "" | Select-Object VMName, Hostname, IPAddress, OS, Boottime, VMState, TotalCPU, CPUAffinity,
CPUHotAdd, CPUShare, CPUlimit, OverallCpuUsage, CPUreservation, TotalMemory, MemoryShare, MemoryUsage,
MemoryHotAdd, MemoryLimit, MemoryReservation, Swapped, Ballooned, Compressed, TotalNics, ToolsStatus,
ToolsVersion, HardwareVersion, TimeSync, CBT, Portgroup, VMHost, Datastore,
Notes, FaultTolerance
$vms.VMName = $vm.Name
$vms.Hostname = $vm.guest.hostname
$vms.IPAddress = $vm.guest.ipAddress
$vms.OS = $vm.Config.GuestFullName
$vms.Boottime = $vm.Runtime.BootTime
$vms.VMState = $vm.summary.runtime.powerState
$vms.TotalCPU = $vm.summary.config.numcpu
$vms.CPUAffinity = $vm.Config.CpuAffinity
$vms.CPUHotAdd = $vm.Config.CpuHotAddEnabled
$vms.CPUShare = $vm.Config.CpuAllocation.Shares.Level
$vms.TotalMemory = $vm.summary.config.memorysizemb
$vms.MemoryHotAdd = $vm.Config.MemoryHotAddEnabled
$vms.MemoryShare = $vm.Config.MemoryAllocation.Shares.Level
$vms.TotalNics = $vm.summary.config.numEthernetCards
$vms.OverallCpuUsage = $vm.summary.quickStats.OverallCpuUsage
$vms.MemoryUsage = $vm.summary.quickStats.guestMemoryUsage
$vms.ToolsStatus = $vm.guest.toolsstatus
$vms.ToolsVersion = $vm.config.tools.toolsversion
$vms.TimeSync = $vm.Config.Tools.SyncTimeWithHost
$vms.HardwareVersion = $vm.config.Version
$vms.MemoryLimit = $vm.resourceconfig.memoryallocation.limit
$vms.MemoryReservation = $vm.resourceconfig.memoryallocation.reservation
$vms.CPUreservation = $vm.resourceconfig.cpuallocation.reservation
$vms.CPUlimit = $vm.resourceconfig.cpuallocation.limit
$vms.CBT = $vm.Config.ChangeTrackingEnabled
$vms.Swapped = $vm.Summary.QuickStats.SwappedMemory
$vms.Ballooned = $vm.Summary.QuickStats.BalloonedMemory
$vms.Compressed = $vm.Summary.QuickStats.CompressedMemory
$vms.Portgroup = Get-View -Id $vm.Network -Property Name | select -ExpandProperty Name
$vms.VMHost = Get-View -Id $vm.Runtime.Host -property Name | select -ExpandProperty Name
$vms.Datastore = $vm.Config.DatastoreUrl[0].Name
$vms.Notes = $vm.Config.Annotation
$vms.FaultTolerance = $vm.Runtime.FaultToleranceState
$Report += $vms
}
$Report = $Report | Sort-Object VMName
IF ($Report -ne "") {
$report | Export-Csv -path tor-vcn2-vm.csv -NoTypeInformation
}
Those are rather vague requirements.
A quick option could be
$sMail = @{
From = 'from@domain'
To = 'to@domain'
Subject = 'VM Report'
Body = Get-VM | Select * | ConvertTo-Html | Out-String
BodyAsHtml = $true
SmtpServer = 'mail.domain'
}
Send-MailMessage @smail
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You change the requirements while I submit a solution?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your reply. Actually, after posting a question, i got some script which looks good for me, just need to add some fileds, could you please add some fields like CpuUsage (Mhz), MemoryUsage (GB), Provisioned Space, Used Space, HA Protection, Consolidation status, VM ID
I'm pretty sure all those extra properties have been discussed before in this community.
Since you seem to be able to perform a search, go for it.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
didn't get into a good readable format😔
$sMail = @{ From = 'from@domain' To = 'to@domain' Subject = 'VM Report' Body = Get-VM | Select * | ConvertTo-Html | Out-String BodyAsHtml = $true SmtpServer = 'mail.domain' } Send-MailMessage @smailI have searched that, but couldn't find all my required fields😞
can anyone help on this please?
Thanks!