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 :
VMName | OS Hostname | DOMAIN | LAN IP | BACKUP IP | VMState | CPU | Memory | vCenter | VMHost | Hard disk1 | Hard disk2 |
---|---|---|---|---|---|---|---|---|---|---|---|
TestVM01 | TestVM01 | TRUE | 10.100.10.12 | 192.168.172.12 | PoweredON | 4 | 16 | 192.168.100.10 | 192.168.30.10 | 50GB | not defined |
TestVM02 | TestVM02 | WORKGROUP | 10.100.10.13 | not defined | PoweredON | 6 | 24 | 192.168.100.10 | 192.168.30.11 | 100GB | 500GB |
You can use Send-MailMessage which is feature in powershell. see link below
To make the body of email appear as table you could try using ConvertTo-Html for powershell.
Moderator: Please do not post duplicate threads.
Notification mail after deploy
Thread locked.