List VM settings to CSV, HTML, gridview, screen and email

 

This PowerCLI script will display specified VM settings for all VMs in the vCenter server you specify. If you do an inventory, a health check or need to troubleshoot VMware environment this PowerCLI script can be useful.

The following VM settings will be displayed:

VMName, Hostname, IP address, OS version, Boottime, VMstate, Total vCPUs, CPU afinnity, CPU hot add status, CPU share, CPU limit, Overall CPU usage, CPU reservation, Total memory, Memory share, Memory usage, Memory hot add status, Memory limit, Memory reservation, Memory swap, Memory ballooning, Memory compression, Total NICs, VMware tools status, VMware Tools version, VM hardware version, Timesync status and CBT status.

 

The output can be specified in the scripts. The following formats:

– CSV

– HTML

image

– GridView. The cool about gridview is that you can easily sort and filter columns.

2011-06-09 11h44_42

– On screen

– HTML file can be send by email.

Requirements:

– Microsoft Powershell v2.0

– VMware PowerCLI 4.1 U1 build 332441

What do I need to change:

The following variables can be changed to suit your needs:

001
002
003
004
005
006
007
008
009
010
011
012
013
# Variable to change
$CreateCSV= "yes"
$GridView = "yes"
$HTML = "yes"
$DisplayHTMLOnScreen = "yes"
$EmailHTML = "yes"
$SendEmail = "yes"
$EmailFrom = "vm@ivobeerens.nl"
$EmailTo = "info@ivobeerens.nl"
$EmailSubject = "VMs settings information"
$EmailSMTP = "smtpserver"
$FileHTML = New-Item -type file "D:\temp\VMInfo_$datefile.html"
$FileCSV = New-Item -type file "D:\temo\VMInfo_$datefile.csv"

 

The PowerCLI script listing:

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<#
.SYNOPSIS
Displays VM settings

.DESCRIPTION
Display VM settings by CSV, HTML, GridView, screen and as HTML by email
 
.Author(s)
Ivo Beerens www.ivobeerens.nl

.EXAMPLE
PS C:\> ./vminfo.ps1

#>

#Initialize PowerCLI
Add-PSSnapin VMware.VimAutomation.Core
C:\"Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1" 

#Connect to vCenter
$VCServer = Read-Host "Enter the vCenter server name"
$Username= Read-Host "Enter the username"
$Password = Read-Host "Enter password"
Connect-VIServer $VCServer -User $username -Password $password -port 443

#Variables
$Date = get-date
$Datefile = ( get-date ).ToString(‘yyyy-MM-dd-hhmmss’)
$ErrorActionPreference = "SilentlyContinue"
# Variable to change
$CreateCSV= "yes"
$GridView = "yes"
$HTML = "yes"
$DisplayHTMLOnScreen = "yes"
$EmailHTML = "yes"
$SendEmail = "yes"
$EmailFrom = "vm@ivobeerens.nl"
$EmailTo = "info@ivobeerens.nl"
$EmailSubject = "VMs settings information"
$EmailSMTP = "smtpserver"
$FileHTML = New-Item -type file "D:\temp\VMInfo_$datefile.html"
$FileCSV = New-Item -type file "D:\temo\VMInfo_$datefile.csv"

#Add Text to the HTML file
Function Create-HTMLTable
{
param([array]$Array)
$arrHTML = $Array | ConvertTo-Html
$arrHTML[-1] = $arrHTML[-1].ToString().Replace(‘</body></html>’,"")
Return $arrHTML[5..2000]
}

$output = @()
$output += ‘<html><head></head><body>’
$output += 
‘<style>table{border-style:solid;border-width:1px;font-size:8pt;background-color:#ccc;width:100%;}th{text-align:left;}td{background-color:#fff;width:20%;border-style:so
lid;border-width:1px;}body{font-family:verdana;font-size:12pt;}h1{font-size:12pt;}h2{font-size:10pt;}</style>’

$output += ‘<H1>VMware VM information</H1>’
$output += ‘<H2>Date and time</H2>’,$date

#Gathering VM settings
Write-Host "Gathering VM statistics"
$Report = @()
Get-VM | Sort Name -Descending | %

 {
 
 
$vm = Get-View $_.
ID
   
$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
    $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
$Report += $vms
}

#Output
if ($GridView -eq "yes") {
$report | Out-GridView }

if ($CreateCSV -eq "yes") {
$report | Export-Csv $FileCSV -NoTypeInformation }

if ($HTML -eq "yes") {
$output += ‘<p>’
$output += ‘<H2>VMware VM information</H2>’
$output += ‘<p>’
$output += Create-HTMLTable 
$report
$output
 += ‘</p>’
$output += ‘</body></html>’
$output | Out-File $FileHTML }

if ($DisplayHTMLOnScreen -eq "yes") {
ii $FileHTML}

if ($SendEmail -eq "yes") {
Send-MailMessage –From $EmailFrom –To $EmailTo –Subject $EmailSubject –SmtpServer $EmailSMTP -Attachments $FileHTML }

#Disconnect session from VC
Disconnect-VIserver -Confirm:$false

 

Download link

10 thoughts on “List VM settings to CSV, HTML, gridview, screen and email”

  1. Running the script and having a few issues. Still kinda new to powercli.

    Why does it stop and ask for Process[0]?

  2. Trouble with “{“! Ccript work, if change to:
    Get-VM | Sort Name -Descending | % {
    $vm = Get-View $_.ID
    $vms = “………………….
    ****
    ***
    ***
    }

  3. Hi,

    just found your script, would it be possible to get info on the disk of the vms?
    I need to get the sum of all the configured virtual disk.
    Can this be done?

  4. You need to change line 065 + 066 + 067 into one line 🙂

    It should be as following:
    Get-VM | Sort Name -Descending | %{

    Otherwise the foreach won’t have any vm, which it can gather details from

    Happy hunting!

  5. The script seems work well. I had the issue above where it complained of process [0] so I made the fix. Now, The report grid displays but I do not get a csv, html, or email. Any pointers for me. The variables were changed to my server and local file location c:\vmware\file1, file2…

  6. Will this script work with the new 5.5 powecli? I am looking for a script that can do the export plus also the Tags. For us its a way to export the vm guest list and tell each project which servers they have on their account and what the costs are.

  7. List VM settings to CSV, HTML, gridview, screen and email | https://www.ivobeerens.nlwww.ivobeerens.nl ugg bailey bow uwbekvrsvk uggs bailey bow armssaint ugg boots cheap lixmns uggs outlet yxhxkkkg botte ugg bbxsctef ugg france xkkfws moncler outlet ohmsfymhe ugg bailey bow nfiouz bailey bow uggs women yjbbsd ugg bailey bow women pgaudpmeho ugg bailey bow hvxdjhtn Ugg Kensington Boots zoelqhhby Bailey Button Ugg ylfbhzviuw Bailey Button rrqgehgr Mens Ugg Boots xinhywfjzbt Uggs for Men syulokvflo Uggs Sale mafvypflybv bailey bow uggs women wubpfcmpcqd uggs bailey bow gmrerqouupr ugg bailey bow women rvkepu outlet woolrich
    bow uggs http://sotoaviation.com/En/BlueBaileyBowUgg/

  8. Works well on PowerCli 6.5, after merging line 65 to 67 as suggested by Nickolej.
    I’m so impressed when I saw the report open!

  9. @Brandon , could you please post the update work full script , still I’m getting error

Leave a Comment