I wrote this as part of a much larger VM deployment script. I thought it may be useful for others looking to do the same. The information I’m sending in the email is Name, IP Address, Memory, CPU, which ESXi Host it’s currently on (needed for setting up backups with EMC NetWorker), and Operating system.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<#	
	.NOTES
	===========================================================================
	 Created with: 	SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.123
	 Created on:   	6/30/2016 11:40 AM
	 Created by:   	Cole Lavallee
	 Filename:     	Get-NewVMInfo.ps1
	===========================================================================
	.DESCRIPTION
		Collects info on a newly deployed VM and sends the email in HTML table. 
        This is part of a larger script that I've written, but may be useful for 
        others.
#>
###############Set Variables###############
Connect-VIServer $vserver
$VMname = "VMName"
$date = Get-Date

################Collecting Name, IP,Memory, CPU Count, ESX Host and Operating Systems of VM################
$NewVM = Get-VM $VMname | Select-Object `
				@{ Name = 'Name'; Expression = { $_.Name } },`
				@{ N = 'IP Address'; E = { @($_.guest.IPAddress[0]) } },`
				@{ N = 'Memory'; E = { $_.MemoryGB } }, `
				@{ N = 'CPU Count'; E = { $_.NumCPU } }, `
				@{ N = 'ESX Host'; E = { $_.VMHost } }, `
				@{ N = 'Operating System'; E = { $_.guest.OSFullName } }

###############HTML Style Settings###############                                        

$a = ""

$html = $NewVM | ConvertTo-HTML -Head $a -Body "

<H2>
  New Virtual Machine Deployed: $($VMname)
</H2> 

<H4>
  Please create change control record and add to backups.
</H4>" | Out-String


###############Send Email###############

Send-MailMessage -SmtpServer smtpserver -From server@domain.com -To user@domain.com -Subject "New Virtual Machine Deployed $($VMname)" -BodyAsHtml $html