VMware Cloud Community
arbelac
Contributor
Contributor

VM Deploy notification

Hi,

I want to send notification mail after vm deploy like below.

My question is :

I have $diskSizes variable. A VM have one or more disks. $diskSizes[0 -> Hard disk 2] , $diskSizes[1 -> Hard disk 3] and so on.  How can I add  HD sizes into the PSCustomObject ?

My script:

    $VCServer = Read-Host "Enter the vCenter server name"

  

    Import-Csv -Path C:\temp\vmdeploy.csv -UseCulture -PipelineVariable row |

  

    ForEach-Object -Process {

  

    New-Vm .... blah blah

  

      $diskSizes = @()

    do {

    $diskSize = Read-Host -Prompt "Additional disk (size in GB or 'no' to stop)"

    if($diskSize -ne 'no'){

    $diskSizes += $diskSize

    }

  

    }

    until($diskSize -eq 'no')

  

      if($diskSizes.Count -gt 0){

      $diskSizes | %{

  

    New-HardDisk -VM $row.ServerName -CapacityGB $_ | Out-Null

  

      }

  

    }

 

Write-Host "Virtual Machine $Hostname Deployed. Powering On"

Start-VM -VM $row.ServerName | Out-Null

.\WaitVmCustomization.ps1 -vmList $row.ServerName -timeoutSeconds 600

     Start-Sleep -seconds 20

 

    ...

# get the report for the VMs

$Report = [PSCustomObject]@{

        'VMName'      = $row.ServerName

        'OS'          = $row.ServerName

        'DOMAIN'      = if ($row.DOMAIN -eq 'Y') { 'TRUE' } else { 'WORKGROUP' }

        'LAN IP'      = $row.LANIP

        'BACKUP IP'   = if ($row.BACKUPIP -eq 'N') { 'not defined' } else { $row.BACKUPIP }

        'VMState'     = (Get-VM -Name $row.ServerName).summary.runtime.powerState

        'TotalCPU'    = $row.NumCPU

        'Totalmemory' = $row.MemoryGB

        'vCenter'     = $VCServer

        'VMHost'      = $row.ESXHOST

    }

 

    Send-MailMessage .....

  

    }

My CSV File:

    ServerName  ESXHOST   Datastore OSCapacityGB NumCPU MemoryGB NetworkName Second Network Adapter LANIP LANGW BACKUPIP DOMAIN

    TestVM01,192.168.30.10,LUNPRDVM01,50,4,16,PG_VLAN_250,Y,10.100.10.12,255.255.255.0,192.168.172.12,Y

    TestVM02,192.168.30.11,LUNPRDVM02,60,6,24,PG_VLAN_250,N,10.100.10.13,255.255.255.0,N,N

My desired notification mail :

VMNameOS Hostname
DOMAIN
LAN IP
BACKUP IP
VMStateCPUMemoryvCenterVMHostHard disk1Hard disk2
TestVM01TestVM01TRUE10.100.10.12192.168.172.12PoweredON416192.168.100.10192.168.30.1050GBnot defined
TestVM02TestVM02WORKGROUP10.100.10.13not definedPoweredON624192.168.100.10192.168.30.11100GB500GB
0 Kudos
2 Replies
MC2016
Enthusiast
Enthusiast

You can use Send-MailMessage which is feature in powershell. see link below

Send-MailMessage

To make the body of email appear as table you could try using ConvertTo-Html​ for powershell.

ConvertTo-Html

0 Kudos
scott28tt
VMware Employee
VMware Employee

Moderator: Please do not post duplicate threads.

Notification mail after deploy

Thread locked.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos