Added email notification

Email at end of DC & VC Builds
TCP port 1433 fixed for SQL V11
Shutdown script improvements
pull/45/head
DemitasseNZ 2016-04-14 08:56:06 +12:00
parent d9179f0bfc
commit 5dd6223462
7 changed files with 61 additions and 18 deletions

View File

@ -37,6 +37,8 @@ if (Test-Path B:\Automate\automate.ini) {
Write-BuildLog "Change default local administrator password" Write-BuildLog "Change default local administrator password"
net user administrator $AdminPWD net user administrator $AdminPWD
B:\automate\_Common\Autologon administrator lab $AdminPWD B:\automate\_Common\Autologon administrator lab $AdminPWD
$emailto = ((Select-String -SimpleMatch "emailto=" -Path "B:\Automate\automate.ini").line).substring(8)
$SmtpServer = ((Select-String -SimpleMatch "SmtpServer=" -Path "B:\Automate\automate.ini").line).substring(11)
} Else { } Else {
Write-BuildLog "Cannot find Automate.ini, this isn't a good sign" Write-BuildLog "Cannot find Automate.ini, this isn't a good sign"
} }
@ -461,6 +463,7 @@ If (((([System.Environment]::OSVersion.Version.Major *10) +[System.Environment]:
Write-BuildLog "The version of SQL Management Studio on the Build share is incompatible with SQL Server 2008 Express R2 SP1. Please see ReadMe.html on the Build share." Write-BuildLog "The version of SQL Management Studio on the Build share is incompatible with SQL Server 2008 Express R2 SP1. Please see ReadMe.html on the Build share."
} else { } else {
Write-BuildLog "SQL Management Studio found; installing." Write-BuildLog "SQL Management Studio found; installing."
Install-WindowsFeature Net-Framework-Core
Start-Process B:\SQLManagementStudio_x64_ENU.exe -ArgumentList "/ACTION=INSTALL /IACCEPTSQLSERVERLICENSETERMS /FEATURES=Tools /q" -Wait -Verb RunAs Start-Process B:\SQLManagementStudio_x64_ENU.exe -ArgumentList "/ACTION=INSTALL /IACCEPTSQLSERVERLICENSETERMS /FEATURES=Tools /q" -Wait -Verb RunAs
} }
} else { Write-BuildLog "SQL Management Studio not found (optional)."} } else { Write-BuildLog "SQL Management Studio not found (optional)."}
@ -531,19 +534,19 @@ if (Test-Path -Path "B:\VMTools\setup*") {
$vcinstall = ((Select-String -SimpleMatch "VCInstall=" -Path "B:\Automate\automate.ini").line).substring(10) $vcinstall = ((Select-String -SimpleMatch "VCInstall=" -Path "B:\Automate\automate.ini").line).substring(10)
switch ($vcinstall) { switch ($vcinstall) {
60 { 60 {
B:\Automate\_Common\wget.exe -nd http://packages.vmware.com/tools/esx/6.0/windows/VMware-tools-windows-9.10.0-2476743.iso -awget.log B:\Automate\_Common\wget.exe -nd http://packages.vmware.com/tools/esx/6.0/windows/VMware-tools-windows-9.10.0-2476743.iso --no-check-certificate -awget.log
. "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\VMtools\ c:\temp\VMware-tools-windows-9.10.0-2476743.iso >> C:\ExtractLog.txt . "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\VMtools\ c:\temp\VMware-tools-windows-9.10.0-2476743.iso >> C:\ExtractLog.txt
Write-BuildLog "VMware Tools V6.0 Downloaded and extracted to build share." Write-BuildLog "VMware Tools V6.0 Downloaded and extracted to build share."
} 55 { } 55 {
B:\Automate\_Common\wget.exe -nd http://packages.vmware.com/tools/esx/5.5u2/windows/VMware-tools-windows-9.4.10-2068191.iso -awget.log B:\Automate\_Common\wget.exe -nd http://packages.vmware.com/tools/esx/5.5u2/windows/VMware-tools-windows-9.4.10-2068191.iso --no-check-certificate -awget.log
. "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\VMtools\ c:\temp\VMware-tools-windows-9.4.10-2068191.iso >> C:\ExtractLog.txt . "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\VMtools\ c:\temp\VMware-tools-windows-9.4.10-2068191.iso >> C:\ExtractLog.txt
Write-BuildLog "VMware Tools V5.5u2 Downloaded and extracted to build share." Write-BuildLog "VMware Tools V5.5u2 Downloaded and extracted to build share."
} 51 { } 51 {
B:\Automate\_Common\wget.exe -nd http://packages.vmware.com/tools/esx/5.1u3/windows/x64/VMware-tools-windows-9.0.15-2323214.iso -awget.log B:\Automate\_Common\wget.exe -nd http://packages.vmware.com/tools/esx/5.1u3/windows/x64/VMware-tools-windows-9.0.15-2323214.iso --no-check-certificate -awget.log
. "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\VMtools\ c:\temp\VMware-tools-windows-9.0.15-2323214.iso >> C:\ExtractLog.txt . "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\VMtools\ c:\temp\VMware-tools-windows-9.0.15-2323214.iso >> C:\ExtractLog.txt
Write-BuildLog "VMware Tools V5.1u3 Downloaded and extracted to build share." Write-BuildLog "VMware Tools V5.1u3 Downloaded and extracted to build share."
} 50 { } 50 {
B:\Automate\_Common\wget.exe -nd http://packages.vmware.com/tools/esx/5.0u3/windows/x64/VMware-tools-windows-8.6.11-1310128.iso -awget.log B:\Automate\_Common\wget.exe -nd http://packages.vmware.com/tools/esx/5.0u3/windows/x64/VMware-tools-windows-8.6.11-1310128.iso --no-check-certificate -awget.log
. "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\VMtools\ c:\temp\VMware-tools-windows-8.6.11-1310128.iso >> C:\ExtractLog.txt . "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\VMtools\ c:\temp\VMware-tools-windows-8.6.11-1310128.iso >> C:\ExtractLog.txt
Write-BuildLog "VMware Tools V5.0u3 Downloaded and extracted to build share." Write-BuildLog "VMware Tools V5.0u3 Downloaded and extracted to build share."
} }
@ -558,7 +561,22 @@ if (Test-Path -Path "B:\VMTools\setup*") {
if (($vmtools) -and (-Not (Test-Path "C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe"))) { if (($vmtools) -and (-Not (Test-Path "C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe"))) {
Write-BuildLog "Installing VMware tools, build complete after reboot." Write-BuildLog "Installing VMware tools, build complete after reboot."
Write-BuildLog "(Re)build vCenter next." Write-BuildLog "(Re)build vCenter next."
if (([bool]($emailto -as [Net.Mail.MailAddress])) -and ($SmtpServer -ne "none")){
$mailmessage = New-Object system.net.mail.mailmessage
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$mailmessage.from = "AutoLab<autolab@labguides.com>"
$mailmessage.To.add($emailto)
$Summary = "Completed AutoLab VM build.`r`n"
$Summary += "The build of $env:computername has finished, installing VMware Tools and rebooting`r`n"
$Summary += "The build log is attached`r`n"
$mailmessage.Subject = "$env:computername VM build finished"
$mailmessage.Body = $Summary
$attach = new-object Net.Mail.Attachment("C:\buildlog.txt", 'text/plain')
$mailmessage.Attachments.Add($attach)
$message.Attachments.Add($attach)
$SMTPClient.Send($mailmessage)
}
Start-Process B:\VMTools\setup64.exe -ArgumentList '/s /v "/qn"' -verb RunAs -Wait Start-Process B:\VMTools\setup64.exe -ArgumentList '/s /v "/qn"' -verb RunAs -Wait
Start-Sleep -Seconds 5 Start-Sleep -Seconds 300
} }
Read-Host "Press <ENTER> to exit" Read-Host "Press <ENTER> to exit"

Binary file not shown.

View File

@ -36,6 +36,23 @@ If ([string]::Compare($ReBuild, "Y", $True) -eq "0"){
exit exit
} }
} }
Write-host "Connect to Linux amchiunes to cache RSA Keys, say yes to all"
$ping = new-object System.Net.NetworkInformation.Ping
$Reply = $ping.send("192.168.199.254")
if ($Reply.status eq "Success") {
Write-Host " WAN" -foregroundcolor "Green"
cmd /c '"C:\Program Files (x86)\PuTTY\plink.exe" 192.168.199.254 -l root -pw VMware1! exit'
}
$Reply = $ping.send("gw")
if (($Reply.status eq "Success") -and (!((get-vmplatform) -ne "Ravello"))) {
Write-Host " Router" -foregroundcolor "Green"
cmd /c '"C:\Program Files (x86)\PuTTY\plink.exe" gw -l root -pw VMware1! exit'
}
$Reply = $ping.send("nas")
if ($Reply.status eq "Success") {
Write-Host " NAS" -foregroundcolor "Green"
cmd /c '"C:\Program Files (x86)\PuTTY\plink.exe" NAS -l root -pw VMware1! exit'
}
Write-Host "Connect to vCenter" -foregroundcolor "Green" Write-Host "Connect to vCenter" -foregroundcolor "Green"
$null = connect-viserver vc.lab.local -user administrator -password $AdminPWD $null = connect-viserver vc.lab.local -user administrator -password $AdminPWD
Write-Host "Shutdown any running VMs" -foregroundcolor "Green" Write-Host "Shutdown any running VMs" -foregroundcolor "Green"
@ -49,7 +66,6 @@ If ([string]::Compare($ReBuild, "Y", $True) -eq "0"){
ShutWinServ ("cs2.lab.local") ShutWinServ ("cs2.lab.local")
ShutWinServ ("v1.lab.local") ShutWinServ ("v1.lab.local")
ShutWinServ ("vbr.lab.local") ShutWinServ ("vbr.lab.local")
$ping = new-object System.Net.NetworkInformation.Ping
$Reply = $ping.send("vc2.lab.local") $Reply = $ping.send("vc2.lab.local")
if ($Reply.status eq "Success") { if ($Reply.status eq "Success") {
Write-Host "Shutdown SRM Site" -foregroundcolor "Green" Write-Host "Shutdown SRM Site" -foregroundcolor "Green"
@ -76,11 +92,6 @@ If ([string]::Compare($ReBuild, "Y", $True) -eq "0"){
Write-Host "Shutdown NAS" -foregroundcolor "Green" Write-Host "Shutdown NAS" -foregroundcolor "Green"
cmd /c '"C:\Program Files (x86)\PuTTY\plink.exe" NAS -l root -pw VMware1! shutdown -h now' cmd /c '"C:\Program Files (x86)\PuTTY\plink.exe" NAS -l root -pw VMware1! shutdown -h now'
} }
$Reply = $ping.send("vcd")
if ($Reply.status eq "Success") {
Write-Host "Shutdown vCloud" -foregroundcolor "Green"
cmd /c '"C:\Program Files (x86)\PuTTY\plink.exe" vcd -l root -pw VMware1! shutdown -h now'
}
ShutWinServ ("dc2.lab.local") ShutWinServ ("dc2.lab.local")
ShutWinServ ("dc.lab.local") ShutWinServ ("dc.lab.local")
ShutWinServ ("vc2.lab.local") ShutWinServ ("vc2.lab.local")

View File

@ -102,6 +102,8 @@ if (Test-Path "B:\Automate\automate.ini") {
} }
$AdminPWD = "VMware1!" $AdminPWD = "VMware1!"
$AdminPWD = ((Select-String -SimpleMatch "Adminpwd=" -Path "B:\Automate\automate.ini").line).substring(9) $AdminPWD = ((Select-String -SimpleMatch "Adminpwd=" -Path "B:\Automate\automate.ini").line).substring(9)
$emailto = ((Select-String -SimpleMatch "emailto=" -Path "B:\Automate\automate.ini").line).substring(8)
$SmtpServer = ((Select-String -SimpleMatch "SmtpServer=" -Path "B:\Automate\automate.ini").line).substring(11)
} else { } else {
Write-BuidLog "Unable to find B:\Automate\automate.ini. Where did it go?" Write-BuidLog "Unable to find B:\Automate\automate.ini. Where did it go?"
} }
@ -646,6 +648,20 @@ If ($AutovCNS -eq "True"){
Write-BuildLog "Installing VMware tools, build complete after reboot." Write-BuildLog "Installing VMware tools, build complete after reboot."
if (Test-Path B:\VMTools\setup64.exe) { if (Test-Path B:\VMTools\setup64.exe) {
#Read-Host "End of install checkpoint, before VMTools" #Read-Host "End of install checkpoint, before VMTools"
if (([bool]($emailto -as [Net.Mail.MailAddress])) -and ($SmtpServer -ne "none")){
$mailmessage = New-Object system.net.mail.mailmessage
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$mailmessage.from = "AutoLab<autolab@labguides.com>"
$mailmessage.To.add($emailto)
$Summary = "Completed AutoLab VM build.`r`n"
$Summary += "The build of $env:computername has finished, installing VMware Tools and rebooting`r`n"
$Summary += "The build log is attached`r`n"
$mailmessage.Subject = "$env:computername VM build finished"
$mailmessage.Body = $Summary
$attach = new-object Net.Mail.Attachment("C:\buildlog.txt", 'text/plain')
$mailmessage.Attachments.Add($attach)
$SMTPClient.Send($mailmessage)
}
Start-Process B:\VMTools\setup64.exe -ArgumentList '/s /v "/qn"' -verb RunAs -Wait Start-Process B:\VMTools\setup64.exe -ArgumentList '/s /v "/qn"' -verb RunAs -Wait
} }

View File

@ -53,7 +53,6 @@ if ($CompName -eq "DC") {
} }
net user SVC_Veeam $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log net user SVC_Veeam $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log
net user SVC_SRM $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log net user SVC_SRM $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log
net user SVC_vCD $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log
net user DomUser $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log net user DomUser $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log
net user vi-admin $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log net user vi-admin $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log
net user administrator $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log net user administrator $AdminPWD >> C:\AD-Users.log 2>> C:\Error.log
@ -246,9 +245,6 @@ if ($CompName -eq "DC") {
Check-DNSRecord ("nas.lab.local") Check-DNSRecord ("nas.lab.local")
Check-DNSRecord ("host1.lab.local") Check-DNSRecord ("host1.lab.local")
Check-DNSRecord ("host2.lab.local") Check-DNSRecord ("host2.lab.local")
Check-DNSRecord ("vcd.lab.local")
Check-DNSRecord ("vcd-proxy.lab.local")
Check-DNSRecord ("vshield.lab.local")
Check-DNSRecord ("192.168.199.4") Check-DNSRecord ("192.168.199.4")
Check-DNSRecord ("192.168.199.5") Check-DNSRecord ("192.168.199.5")
Check-DNSRecord ("192.168.199.6") Check-DNSRecord ("192.168.199.6")
@ -328,9 +324,6 @@ if ($CompName -eq "DC2") {
Check-DNSRecord ("nas.lab.local") Check-DNSRecord ("nas.lab.local")
Check-DNSRecord ("host1.lab.local") Check-DNSRecord ("host1.lab.local")
Check-DNSRecord ("host2.lab.local") Check-DNSRecord ("host2.lab.local")
Check-DNSRecord ("vcd.lab.local")
Check-DNSRecord ("vcd-proxy.lab.local")
Check-DNSRecord ("vshield.lab.local")
Check-DNSRecord ("192.168.199.4") Check-DNSRecord ("192.168.199.4")
Check-DNSRecord ("192.168.199.5") Check-DNSRecord ("192.168.199.5")
Check-DNSRecord ("192.168.199.6") Check-DNSRecord ("192.168.199.6")

View File

@ -20,3 +20,5 @@ ViewVMProductKey=XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
KMSIP=0.0.0.0 KMSIP=0.0.0.0
emailto=none
SmtpServer=none

View File

@ -1,3 +1,6 @@
Version xx
- Added Email notification for VC & DC build. Specify destination address & SMTP server in autolmate.ini
Version 2.6 Version 2.6
- Support for vSphere 6.0 - Support for vSphere 6.0
- Nested 2012 Server VM - Nested 2012 Server VM