Version 3.0 initial commit

- Support for vSphere 6.5 & 6.7
- Support for Windows Server 2016
- Removed support for Windows Server 2008
- Added Email notification for VC & DC build. Specify destination address & SMTP server in autolmate.ini
- Changed router to pfSense
- Updated NAS to FreeNAS 11.1
- Support for View 7.5
- Nested 2008, 2016, Windows 7, Windows 8, & Windows 10 VMs
master
DemitasseNZ 2018-06-24 16:42:53 +12:00
parent ce80804955
commit 945c87edba
80 changed files with 1803 additions and 1164 deletions

View File

@ -11,22 +11,11 @@ if (Test-Path C:\PSFunctions.ps1) {
Read-Host "Press <Enter> to exit"
exit
}
#if ((Test-Administrator) -and (Test-Path "C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe")) {
# Write-BuildLog " "
# Write-BuildLog "This script should not be 'Run As Administrator'"
# Write-BuildLog " "
# Write-BuildLog "Just double click the shortcut"
# Write-BuildLog " "
# Read-Host "Press <Enter> to exit"
# exit
#}
$a = (Get-Host).UI.RawUI
$b = $a.WindowSize
$b.Height = $a.MaxWindowSize.Height -1
$a.WindowSize = $b
# WASP is a 64bit plugin, the Guest Cust. PowerCLI commands are only 32bit
#import-module C:\windows\system32\WASP.dll
#select-window -Title "Administrator: C:\*" | set-windowposition -left 3 -top 3
$Subnet = ((Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .).IPAddress[0]).split(".")[2]
If ($Subnet -eq "199") {
@ -44,18 +33,18 @@ If ($Subnet -eq "201") {
$SRM = $True
}
if ((Get-Service vpxd).Status -eq "Starting") {
if ((Get-Service vpxd -ErrorAction SilentlyContinue).Status -eq "Starting") {
Write-BuildLog "The vCenter service is still starting; script will pause until service has started."
do {
Start-Sleep -Seconds 30
} until ((Get-Service vpxd).Status -eq "Running")
} elseif ((Get-Service vpxd).Status -eq "Stopped") {
} elseif ((Get-Service vpxd -ErrorAction SilentlyContinue).Status -eq "Stopped") {
Write-BuildLog "The vCenter service is stopped. Please verify the DC VM is powered on and databases have started."
Read-Host "Press <Enter> to exit"
exit
}
if ((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null) {
if (((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null) -and ((Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null)) {
try {
Write-BuildLog "Loading PowerCLI plugin, this may take a little while."
Add-PSSnapin VMware.VimAutomation.Core
@ -65,6 +54,10 @@ if ((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue)
Read-Host "Press <Enter> to exit"
exit
}
} else {
$p += ";C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules"
[Environment]::SetEnvironmentVariable("PSModulePath",$p)
Import-Module "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue
}
for ($i=1;$i -le 4; $i++) {
$vmhost = "$HostPrefix$i.lab.local"
@ -77,11 +70,10 @@ for ($i=1;$i -le 4; $i++) {
}
}
If (!($MaxHosts -ge 2)){
Write-Host "Couldn't find first two hosts to build, need host1 & host2 built before running this script"
Write-BuildLog "Couldn't find first two hosts to build, need host1 & host2 built before running this script"
Read-Host "Build the hosts & rerun this script"
Exit
}
Write-BuildLog " "
If (!(Test-Path "B:\*")) { Net use B: \\nas\Build}
if (Test-Path "B:\Automate\automate.ini") {
Write-BuildLog "Determining automate.ini settings."
@ -91,21 +83,21 @@ if (Test-Path "B:\Automate\automate.ini") {
$createxp = ((Select-String -SimpleMatch "BuildViewVM=" -Path "B:\Automate\automate.ini").line).substring(12).Trim()
if ($createds -like "true") {
$createds = $true
Write-BuildLog " Datastores will be built and added to vCenter."
Write-BuildLog "Datastores will be built and added to vCenter."
} else {
$createds = $false
}
if ($createvm -like "true") {
$createvm = $true
$ProdKey = ((Select-String -SimpleMatch "ProductKey=" -Path "B:\Automate\automate.ini" -List).line).substring(11).Trim()
Write-BuildLog " Windows 2003 VM for Lab will be created."
Write-BuildLog "Windows 2003 VM for Lab will be created."
} else {
$createvm = $false
}
if ($createxp -like "true") {
$createxp = $true
$XPKey = ((Select-String -SimpleMatch "ViewVMProductKey=" -Path "B:\Automate\automate.ini").line).substring(17)
Write-BuildLog " Windows XP VM for VMware View Lab to be built."
Write-BuildLog "Windows XP VM for VMware View Lab to be built."
} else {
$createxp = $false
}
@ -196,9 +188,7 @@ for ($i=1;$i -le $MaxHosts; $i++) {
}
Start-Sleep 5
While ((Get-VMHost $VMHost).ConnectionState -ne "Connected"){
Write-BuildLog " "
Write-BuildLog $VMHost " is not yet connected. Pausing for 5 seconds."
Write-BuildLog " "
Start-Sleep 5
}
$VMHostObj = Get-VMHost $VMHost
@ -274,7 +264,7 @@ for ($i=1;$i -le $MaxHosts; $i++) {
Write-BuildLog "Restarting all hosts for consistency. This will take a few minutes."
$null = Get-VMHost -location $ClusterName | Restart-VMHost -confirm:$false -Force
Write-Host "Wait until all hosts have stopped pinging"
Write-BuildLog "Wait until all hosts have stopped pinging"
$PingStatus = @()
for ($i=1;$i -le $MaxHosts; $i++) {$PingStatus +=$True}
do {
@ -291,7 +281,7 @@ do {
If ($PingStatus[$I-1] -eq $True) {$StayHere = $True}
}
} while ($StayHere)
Write-Host "Wait until all hosts are pinging"
Write-BuildLog "Wait until all hosts are pinging"
do {
Start-Sleep -Seconds 1
$ping = new-object System.Net.NetworkInformation.Ping
@ -306,7 +296,7 @@ do {
If ($PingStatus[$I-1] -eq $False) {$StayHere = $True}
}
} while ($StayHere)
Write-Host "Wait until all hosts are Connected"
Write-BuildLog "Wait until all hosts are Connected"
for ($i=1;$i -le $MaxHosts; $i++) {$PingStatus +=$False}
do {
Start-Sleep -Seconds 1
@ -321,7 +311,7 @@ do {
If ($PingStatus[$I-1] -eq $False) {$StayHere = $True}
}
} while ($StayHere)
Write-Host "Wait 2 minutes so last host is properly up"
Write-BuildLog "Wait 2 minutes so last host is properly up"
start-sleep 120
If ($SRM -ne $True){
if (((Get-OSCustomizationSpec | where {$_.Name -eq "Windows"}) -eq $null) -and ($ProdKey -ne $null) ){
@ -378,131 +368,144 @@ If ($SRM -ne $True){
$Cluster = Get-View $Cluster
$null = $Cluster.ReconfigureComputeResource_Task($spec, $true)
Write-BuildLog "Waiting two minutes for HA to complete configuration."
$Datastore = Get-Datastore -VMhost $vmHost -name "NFS01"
Start-Sleep -Seconds 120
if (!(Get-PSDrive -Name NFS01 -ErrorAction "SilentlyContinue")) {
$null = New-PSDrive -Name NFS01 -PSProvider ViMdatastore -Root '\' -Location $Datastore
}
$VMHostObj = Get-VMHost $VMHost
$VMName="Template2012"
if (($CreateVM) -and ((Get-VM -name $VMName -ErrorAction "SilentlyContinue") -eq $null ) -and (test-path "\\192.168.199.7\build\Win2012.ISO")) {
$Datastore = Get-Datastore -VMhost $vmHost -name "NFS01"
Start-Sleep -Seconds 2
if (!(Get-PSDrive -Name NFS01 -ErrorAction "SilentlyContinue")) {
$null = New-PSDrive -Name NFS01 -PSProvider ViMdatastore -Root '\' -Location $Datastore
}
#Create new VM if existing VM or template doesn't exist
if (!(Test-Path NFS01:\$VMName\$VMName.vmdk)) {
Write-BuildLog "Creating Template2012 VM as Windows Server 2012"
If ((Get-vmhost)[0].version -lt "5.5.0"){
$MyVM = New-VM -Name $VMName -VMhost $vmHost -datastore $Datastore -NumCPU 1 -MemoryMB 768 -DiskMB 16384 -DiskStorageFormat Thin -GuestID windows8Server64Guest
get-networkadapter $MyVM |set-networkadapter -type e1000 -confirm:$false
} Else {
$MyVM = New-VM -Name $VMName -VMhost $vmHost -datastore $Datastore -NumCPU 1 -MemoryMB 768 -DiskMB 16384 -DiskStorageFormat Thin -GuestID windows8Server64Guest -Version "v8"
}
$null = New-CDDrive -VM $MyVM -ISOPath "[Build] /Win2012.ISO" -StartConnected
$null = New-FloppyDrive -VM $MyVM -FloppyImagePath "[Build] Automate/BootFloppies/Nested2012.flp" -StartConnected
$strBootHDiskDeviceName = "Hard disk 1"
$viewVM = Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device -Filter @{"Name" = "^$VMName$"}
## get the VirtualDisk device, then grab its Key (DeviceKey, used later)
$intHDiskDeviceKey = ($viewVM.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq $strBootHDiskDeviceName}).Key
## bootable Disk BootOption device, for use in setting BootOrder (the corresponding VirtualDisk device is bootable, assumed)
$oBootableHDisk = New-Object -TypeName VMware.Vim.VirtualMachineBootOptionsBootableDiskDevice -Property @{"DeviceKey" = $intHDiskDeviceKey}
## bootable CDROM device (per the docs, the first CDROM with bootable media found is used)
$oBootableCDRom = New-Object -Type VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice
## create the VirtualMachineConfigSpec with which to change the VM's boot order
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec -Property @{"BootOptions" = New-Object VMware.Vim.VirtualMachineBootOptions -Property @{BootOrder = $oBootableCDRom, $oBootableHDisk}}
$null = $viewVM.ReconfigVM_Task($spec)
Write-BuildLog "Powering on VM and installing Windows."
$null = Start-VM $MyVM
} else {
Write-BuildLog "Found existing WinTemplate."
if (Test-Path NFS01:\$VMName\$VMName.vmtx) {
Write-BuildLog "Registering existing Template2012 template."
$vmxFile = Get-Item NFS01:\$VMName\$VMName.vmtx
$null = New-Template -VMHost $VMHost -TemplateFilePath $vmxFile.DatastoreFullPath
Write-BuildLog "Existing WinTemplate Template added to inventory."
$HostVer = (([int]((($VMHostObj.Version.Split("."))[0])) *10) + [int]($VMHostObj.Version.Split("."))[1])
foreach ($os in ("2016","2012", "2008", "2K3", "10", "8", "7", "XP")){
$VMName=("Template" + $OS)
if (($CreateVM) -and ((Get-VM -name $VMName -ErrorAction "SilentlyContinue") -eq $null ) -and (test-path ("\\192.168.199.7\build\Win" + $OS + ".iso"))) {
#Create new VM if existing VM or template doesn't exist
if (!(Test-Path NFS01:\$VMName\$VMName.vmdk)) {
$Go = $False
Switch ($OS) {
"2016" {
$GuestID = "windows9Server64Guest"
$GuestRAM = 768
$GuestHDD = 16384
$GuestMinHost = 60
$GuestMaxHost = 99
if (($HostVer -ge $GuestMinHost) -and ($HostVer -le $GuestMaxHost)) {
$Go = $True
$VMHWVer = "v11"
}
}"2012" {
$GuestID = "windows8Server64Guest"
$GuestRAM = 768
$GuestHDD = 16384
$GuestMinHost = 50
$GuestMaxHost = 99
if (($HostVer -ge $GuestMinHost) -and ($HostVer -le $GuestMaxHost)) {
$Go = $True
$VMHWVer = "v8"
}
} "2008" {
$GuestID = "windows7Server64Guest"
$GuestRAM = 768
$GuestHDD = 16384
$GuestMinHost = 40
$GuestMaxHost = 99
if (($HostVer -ge $GuestMinHost) -and ($HostVer -le $GuestMaxHost)) {
$Go = $True
$VMHWVer = "v7"
}
} "2K3" {
$GuestID = "winNetStandard64Guest"
$GuestRAM = 384
$GuestHDD = 3072
$GuestMinHost = 30
$GuestMaxHost = 99
if (($HostVer -ge $GuestMinHost) -and ($HostVer -le $GuestMaxHost)) {
$Go = $True
$VMHWVer = "v7"
}
} "10" {
$GuestID = "windows9_64Guest"
$GuestRAM = 768
$GuestHDD = 16384
$GuestMinHost = 60
$GuestMaxHost = 99
if (($HostVer -ge $GuestMinHost) -and ($HostVer -le $GuestMaxHost)) {
$Go = $True
$VMHWVer = "v11"
}
} "8" {
$GuestID = "windows8_64Guest"
$GuestRAM = 768
$GuestHDD = 16384
$GuestMinHost = 50
$GuestMaxHost = 99
if (($HostVer -ge $GuestMinHost) -and ($HostVer -le $GuestMaxHost)) {
$Go = $True
$VMHWVer = "v8"
}
} "7" {
$GuestID = "windows7_64Guest"
$GuestRAM = 768
$GuestHDD = 16384
$GuestMinHost = 40
$GuestMaxHost = 99
if (($HostVer -ge $GuestMinHost) -and ($HostVer -le $GuestMaxHost)) {
$Go = $True
$VMHWVer = "v7"
}
} "XP" {
$GuestID = "winXPProGuest"
$GuestRAM = 384
$GuestHDD = 3072
$GuestMinHost = 30
$GuestMaxHost = 60
if (($HostVer -ge $GuestMinHost) -and ($HostVer -le $GuestMaxHost)) {
$Go = $True
$VMHWVer = "v7"
}
}
}
If ($Go) {
If ((Get-vmhost)[0].version -lt "5.5.0"){
Write-BuildLog "Creating $VMName VM as Windows $OS"
$MyVM = New-VM -Name $VMName -VMhost $vmHost -datastore $Datastore -NumCPU 1 -MemoryMB $GuestRAM -DiskMB $GuestHDD -DiskStorageFormat Thin -GuestID $GuestID
get-networkadapter $MyVM |set-networkadapter -type e1000 -confirm:$false
} Else {
Write-BuildLog "Creating $VMName VM as Windows $OS"
$MyVM = New-VM -Name $VMName -VMhost $vmHost -datastore $Datastore -NumCPU 1 -MemoryMB $GuestRAM -DiskMB $GuestHDD -DiskStorageFormat Thin -GuestID $GuestID -Version $VMHWVer
}
$BuildISO = "[Build]/Auto" + $OS + ".iso"
if (test-path ("\\192.168.199.7\build\Auto" + $OS + ".iso")) {
$null = New-CDDrive -VM $MyVM -ISOPath $BuildISO -StartConnect
} else {
$BuildISO = "[Build]/Win" + $OS + ".iso"
$null = New-CDDrive -VM $MyVM -ISOPath $BuildISO -StartConnected
$null = New-FloppyDrive -VM $MyVM -FloppyImagePath ("[Build] Automate/BootFloppies/Nested" + $OS + ".flp") -StartConnected
}
$strBootHDiskDeviceName = "Hard disk 1"
$viewVM = Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device -Filter @{"Name" = "^$VMName$"}
$intHDiskDeviceKey = ($viewVM.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq $strBootHDiskDeviceName}).Key
$oBootableHDisk = New-Object -TypeName VMware.Vim.VirtualMachineBootOptionsBootableDiskDevice -Property @{"DeviceKey" = $intHDiskDeviceKey}
$oBootableCDRom = New-Object -Type VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec -Property @{"BootOptions" = New-Object VMware.Vim.VirtualMachineBootOptions -Property @{BootOrder = $oBootableCDRom, $oBootableHDisk}}
$null = $viewVM.ReconfigVM_Task($spec)
$null = Start-VM $MyVM
} else {
Write-BuildLog "Not creating Windows $OS VM"
}
} else {
Write-BuildLog "Found existing $VMName."
if (Test-Path NFS01:\$VMName\$VMName.vmtx) {
Write-BuildLog "Registering existing Template$os template."
$vmxFile = Get-Item NFS01:\$VMName\$VMName.vmtx
$null = New-Template -VMHost $VMHost -TemplateFilePath $vmxFile.DatastoreFullPath
Write-BuildLog "Existing $VMName Template added to inventory."
}
}
Start-Sleep -Seconds 2
}
Start-Sleep -Seconds 2
$null = Remove-PSDrive NFS01
}
$null = Remove-PSDrive NFS01
if ($vmhostObj.version.split(".")[0] -eq "4") {
$Datastore = Get-Datastore -VMhost $vmHost -name "iSCSI2"
$VMName="WinTemplate4"
} else {
$Datastore = Get-Datastore -VMhost $vmHost -name "iSCSI1"
$VMName="WinTemplate"
}
if (($CreateVM) -and ((Get-VM -name $VMName -ErrorAction "SilentlyContinue") -eq $null ) -and (test-path "\\192.168.199.7\build\Auto2K3.ISO")) {
if (!(Get-PSDrive -Name iSCSI1 -ErrorAction "SilentlyContinue")) {
$null = New-PSDrive -Name iSCSI1 -PSProvider ViMdatastore -Root '\' -Location $Datastore
}
Start-Sleep -Seconds 2
#Create new VM if existing VM or template doesn't exist
if (!(Test-Path iSCSI1:\$VMName\$VMName.vmdk)) {
Write-BuildLog "Creating WinTemplate VM Windows Server 2003."
If ((Get-vmhost)[0].version -lt "5.5.0"){
$MyVM = New-VM -Name $VMName -VMhost $vmHost -datastore $Datastore -NumCPU 1 -MemoryMB 384 -DiskMB 3072 -DiskStorageFormat Thin -GuestID winNetEnterpriseGuest
} Else {
$MyVM = New-VM -Name $VMName -VMhost $vmHost -datastore $Datastore -NumCPU 1 -MemoryMB 384 -DiskMB 3072 -DiskStorageFormat Thin -GuestID winNetEnterpriseGuest -Version "v8"
}
$null = New-CDDrive -VM $MyVM -ISOPath "[Build] /Auto2K3.iso" -StartConnected
Write-BuildLog "Powering on VM and installing Windows."
$null = Start-VM $MyVM
} else {
Write-BuildLog "Found existing WinTemplate."
if (Test-Path iSCSI1:\$VMName\$VMName.vmtx) {
Write-BuildLog "Registering existing WinTemplate template."
$vmxFile = Get-Item iSCSI1:\$VMName\$VMName.vmtx
$null = New-Template -VMHost $VMHost -TemplateFilePath $vmxFile.DatastoreFullPath
Write-BuildLog "Existing WinTemplate Template added to inventory."
}
}
Start-Sleep -Seconds 2
$null = Remove-PSDrive iSCSI1
}
$VMName = "WinXP"
$Datastore = Get-Datastore "iSCSI2"
if (($CreateXP) -and ((Get-VM -name $VMName -ErrorAction "SilentlyContinue") -eq $null ) -and (test-path "\\192.168.199.7\build\AutoXP.iso")) {
if (!(Get-PSDrive -Name iSCSI2 -ErrorAction "SilentlyContinue")) {
$null = New-PSDrive -Name iSCSI2 -PSProvider ViMdatastore -Root '\' -Location $Datastore
}
Start-Sleep -Seconds 2
#Create new VM if existing VM or template doesn't exist
if (!(Test-Path iSCSI2:\$VMName\$VMName.vmdk)) {
Write-BuildLog "Creating Windows XP VM for View."
If ((Get-vmhost)[0].version -lt "5.5.0"){
$MyVM = New-VM -Name $VMName -VMhost $vmHost -datastore $Datastore -NumCPU 1 -MemoryMB 384 -GuestID winXPProGuest
} Else {
$MyVM = New-VM -Name $VMName -VMhost $vmHost -datastore $Datastore -NumCPU 1 -MemoryMB 384 -GuestID winXPProGuest -Version "v8"
}
$null = New-CDDrive -VM $MyVM -ISOPath "[Build] /AutoXP.iso" -StartConnected
$null = New-FloppyDrive -VM $MyVM -FloppyImagePath "[Build] Automate/BootFloppies/vmscsi-1.2.0.4.flp" -StartConnected
$strBootHDiskDeviceName = "Hard disk 1"
$viewVM = Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device -Filter @{"Name" = "^$VMName$"}
## get the VirtualDisk device, then grab its Key (DeviceKey, used later)
$intHDiskDeviceKey = ($viewVM.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq $strBootHDiskDeviceName}).Key
## bootable Disk BootOption device, for use in setting BootOrder (the corresponding VirtualDisk device is bootable, assumed)
$oBootableHDisk = New-Object -TypeName VMware.Vim.VirtualMachineBootOptionsBootableDiskDevice -Property @{"DeviceKey" = $intHDiskDeviceKey}
## bootable CDROM device (per the docs, the first CDROM with bootable media found is used)
$oBootableCDRom = New-Object -Type VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice
## create the VirtualMachineConfigSpec with which to change the VM's boot order
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec -Property @{"BootOptions" = New-Object VMware.Vim.VirtualMachineBootOptions -Property @{BootOrder = $oBootableCDRom, $oBootableHDisk}}
$null = $viewVM.ReconfigVM_Task($spec)
$Null = Start-VM $MyVM
} else {
Write-BuildLog "Found existing WinXP."
if (Test-Path iSCSI1:\$VMName\$VMName.vmtx) {
Write-BuildLog "Registering existing WinTemplate template."
$vmxFile = Get-Item iSCSI2:\$VMName\$VMName.vmtx
$null = New-Template -VMHost $VMHost -TemplateFilePath $vmxFile.DatastoreFullPath
Write-BuildLog "Existing WinTemplate Template added to inventory."
}
}
Start-Sleep -Seconds 2
$null = Remove-PSDrive iSCSI2
}
$VMName = "TTYLinux"
if ((Get-VM -name $VMName -ErrorAction "SilentlyContinue") -eq $null ) {
Write-BuildLog "Registering existing tiny TTYLinux VM."
@ -526,10 +529,6 @@ If ($SRM -ne $True){
$null = Remove-PSDrive iSCSI3
}
}
Write-BuildLog " "
$null = Disconnect-VIServer -Server * -confirm:$false
if (Test-Path "C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe") {
Read-Host " Configuration complete, press <Enter> to continue."
}
exit
#Read-Host " All OK?"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,10 +1,10 @@
@echo off
echo *************************
echo *
echo **
echo * Begining Build.cmd as %userdomain%\%username%
echo * Begining Build.cmd as %userdomain%\%username% >> c:\buildlog.txt
echo * Connect to build share
net use B: \\192.168.199.7\Build >> c:\buildlog.txt
type b:\automate\version.txt >> c:\buildlog.txt
if not exist B:\ net use B: \\192.168.199.7\Build
if not exist c:\temp\ md c:\temp
regedit -s b:\Automate\_Common\ExecuPol.reg
regedit -s b:\Automate\_Common\NoSCRNSave.reg
regedit -s B:\Automate\_Common\ExplorerView.reg
@ -13,11 +13,13 @@ regedit -s b:\Automate\_Common\Nested.reg
REG ADD "HKCU\Environment" /V SEE_MASK_NOZONECHECKS /T REG_SZ /D 1 /F
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /V SEE_MASK_NOZONECHECKS /T REG_SZ /D 1 /F
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments " /V SaveZoneInformation /T REG_DWORD /D 1 /F
copy B:\automate\_Common\wasp.dll C:\windows\system32
echo * Activate Windows >> c:\buildlog.txt
cscript //B "%windir%\system32\slmgr.vbs" /ato
copy B:\Automate\PSFunctions.ps1 C:\
copy B:\Automate\validate.ps1 C:\
copy B:\Automate\ViewSetup.ps1 C:\
copy B:\Automate\%computername%\Build.ps1 c:\
echo * Starting PowerShell script for Phase 2 completion
echo * Starting PowerShell script for Phase 2 completion >> C:\buildlog.txt
powershell c:\Build.ps1
if exist C:\Build.ps1 del c:\Build.ps1

View File

@ -6,30 +6,56 @@ if (Test-Path C:\PSFunctions.ps1) {
exit
}
$a = (Get-Host).UI.RawUI
$a.WindowTitle = "CS1 Build Automation"
$b = $a.WindowSize
$b.Height = $a.MaxWindowSize.Height - 1
$a.WindowSize = $b
Import-Module C:\windows\system32\WASP.dll
Select-Window -Title "CS1 Build Automation" | set-windowposition -left 75 -top 3
if (Test-Path "B:\Automate\automate.ini") {
Write-BuildLog "Determining automate.ini settings."
$viewinstall = ((Select-String -SimpleMatch "ViewInstall=" -Path "B:\Automate\automate.ini").line).substring(12)
Write-BuildLog " VMware View install set to $viewinstall."
$timezone = ((Select-String -SimpleMatch "TZ=" -Path "B:\Automate\automate.ini").line).substring(3)
Write-BuildLog " Timezone set to $timezone."
Write-BuildLog "Timezone set to $timezone."
tzutil /s "$timezone"
$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)
}
If (([System.Environment]::OSVersion.Version.Major -eq 6) -and ([System.Environment]::OSVersion.Version.Minor -ge 2)) {
if ((Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain -eq $False) {
Write-BuildLog "Joining domain"
B:\automate\_Common\Autologon administrator lab $AdminPWD
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Build /t REG_SZ /d "cmd /c c:\Build.cmd" /f
$password = $AdminPWD | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("administrator",$password)
$null = Add-Computer -DomainName "lab.local" -Credential $credential -restart
read-host "Wait for restart"
} else {
regedit /s b:\Automate\_Common\ExecuPol.reg
regedit -s b:\Automate\_Common\NoSCRNSave.reg
Write-BuildLog "Change default local administrator password"
net user administrator $AdminPWD
B:\automate\_Common\Autologon administrator lab $AdminPWD
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Build /f
}
If ((([System.Environment]::OSVersion.Version.Major *10) + [System.Environment]::OSVersion.Version.Minor) -ge 62) {
Write-BuildLog "Disabling autorun of ServerManager at logon."
Start-Process schtasks -ArgumentList ' /Change /TN "\Microsoft\Windows\Server Manager\ServerManager" /DISABLE' -Wait -Verb RunAs
Start-Process schtasks -ArgumentList ' /Change /TN "\Microsoft\Windows\Server Manager\ServerManager" /DISABLE' -Wait -Verb RunAs
Write-BuildLog "Disabling screen saver"
set-ItemProperty -path 'HKCU:\Control Panel\Desktop' -name ScreenSaveActive -value 0
Write-BuildLog "Install admin tools"
Add-WindowsFeature RSAT-Feature-Tools,RSAT-DHCP,RSAT-DNS-Server,RSAT-AD-AdminCenter
Write-BuildLog "Enable remote management through firewall"
Netsh firewall set service RemoteAdmin
Netsh advfirewall set currentprofile settings remotemanagement enable
Write-BuildLog "Setup Firewall"
netsh advfirewall firewall add rule name="All ICMP V4" dir=in action=allow protocol=icmpv4
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
}
do {
start-sleep 10
} until ((get-process "msiexec" -ea SilentlyContinue) -eq $Null)
$Files = get-childitem "b:\view$viewinstall"
for ($i=0; $i -lt $files.Count; $i++) {
If ($Files[$i].Name -like "VMware-viewconnectionserver*") {$Installer = $Files[$i].FullName}
@ -38,68 +64,82 @@ Switch ($ViewInstall) {
50 {
Write-BuildLog "Install View 5.0 Connection Server"
Start-Process $Installer -wait -ArgumentList " /s /v'/qn VDM_SERVER_INSTANCE_TYPE=1'"
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
copy b:\automate\ViewSetup.ps1 c:\
start-sleep 60
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe c:\ViewSetup.ps1 >> c:\buildlog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
51 {
Write-BuildLog "Install View 5.1 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qb VDM_SERVER_INSTANCE_TYPE=1 VDM_SERVER_RECOVERY_PWD=VMware1! VDM_SERVER_RECOVERY_PWD2=VMware1! VDM_INITIAL_ADMIN_OPTION=1 CEIP_OPTIN=0"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
52 {
Write-BuildLog "Install View 5.2 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qb VDM_SERVER_INSTANCE_TYPE=1 VDM_SERVER_RECOVERY_PWD=VMware1! VDM_SERVER_RECOVERY_PWD2=VMware1! VDM_INITIAL_ADMIN_OPTION=1 CEIP_OPTIN=0"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
53 {
Write-BuildLog "Install View 5.3 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=1 VDM_SERVER_RECOVERY_PWD=VMware1! VDM_SERVER_RECOVERY_PWD2=VMware1! VDM_INITIAL_ADMIN_OPTION=1 CEIP_OPTIN=0"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
60 {
Write-BuildLog "Install View 6.0 Connection Server"
copy $Installer C:\ViewInstaller.exe
Start-Process C:\ViewInstaller.exe -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=1 FWCHOICE=1 VDM_INITIAL_ADMIN_SID=S-1-5-32-544 VDM_SERVER_RECOVERY_PWD=VMware1 VDM_SERVER_RECOVERY_PWD_REMINDER=First"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
if (([System.Environment]::OSVersion.Version.Major -eq 6) -and ([System.Environment]::OSVersion.Version.Minor -ge 3)) {
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}else {
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
}
70 {
Write-BuildLog "Install View 7.0 Connection Server"
copy $Installer C:\ViewInstaller.exe
Start-Process C:\ViewInstaller.exe -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=1 FWCHOICE=1 VDM_INITIAL_ADMIN_SID=S-1-5-32-544 VDM_SERVER_RECOVERY_PWD=VMware1 VDM_SERVER_RECOVERY_PWD_REMINDER=First"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
if ([System.Environment]::OSVersion.Version.Major -ge 9) {
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}else {
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
} 75 {
Write-BuildLog "Install View 7.5 Connection Server"
copy $Installer C:\ViewInstaller.exe
Start-Process C:\ViewInstaller.exe -wait -ArgumentList '/v"/qb VDM_SERVER_INSTANCE_TYPE=1 FWCHOICE=1 VDM_INITIAL_ADMIN_SID=S-1-5-32-544 VDM_SERVER_RECOVERY_PWD=VMware1 VDM_SERVER_RECOVERY_PWD_REMINDER=First VDM_IP_PROTOCOL_USAG=IPv4 HTMLACCESS=1"'
if ([System.Environment]::OSVersion.Version.Major -ge 9) {
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}else {
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
}
}
browserAndFlash
$PCLIver = deployPowerCLI
if (($PCLIver -ge 65) -and ($viewinstall -ge 70) -and ([System.Environment]::OSVersion.Version.Major -ge 10)){
copy-item -path b:\automate\cs1\ConfigView.ps1 -destination c:\
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Config /t REG_SZ /d 'powershell.exe c:\ConfigView.ps1' /f
} else {
start-process powershell.exe -ArgumentList " C:\viewsetup.ps1" -redirectstandardoutput "C:\ViewLog.txt" -Wait
Get-Content "C:\ViewLog.txt" | Out-File "C:\BuildLog.txt" -Append
if (([bool]($emailto -as [Net.Mail.MailAddress])) -and ($SmtpServer -ne "none")){
Write-BuildLog "Emailing log"
$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")
$mailmessage.Attachments.Add($attach)
$SMTPClient.Send($mailmessage)
$mailmessage.dispose()
$SMTPClient.dispose()
}
}
Write-BuildLog "Install Flash Player"
Start-Process msiexec -wait -ArgumentList " /i b:\Automate\_Common\install_flash_player_11_active_x.msi /qn"
Write-BuildLog "Setup Firewall"
netsh advfirewall firewall add rule name="All ICMP V4" dir=in action=allow protocol=icmpv4
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes
Write-BuildLog "Setup persistet route to other subnet for SRM and View"
route add 192.168.201.0 mask 255.255.255.0 192.168.199.254 -p
Write-BuildLog "Cleanup"
regedit /s b:\Automate\_Common\ExecuPol.reg
regedit -s b:\Automate\_Common\NoSCRNSave.reg
Write-BuildLog "Change default local administrator password"
net user administrator $AdminPWD
B:\automate\_Common\Autologon vi-admin lab $AdminPWD
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Build /f
Write-BuildLog "Install VMware Tools"
b:\VMTools\Setup64.exe /s /v "/qn"
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")
$mailmessage.Attachments.Add($attach)
$SMTPClient.Send($mailmessage)
}
Read-Host "Rebooting after VMTools Install"

View File

@ -0,0 +1,156 @@
If (-Not(Test-Path -path "b:\")) { net use B: \\192.168.199.7\Build}
. "C:\PSFunctions.ps1"
$userID = "vi-admin@lab.local"
$VCHost = 'vc.lab.local'
$url = 'https://' + $VCHost
$AdminPWD = ((Select-String -SimpleMatch "Adminpwd=" -Path "B:\Automate\automate.ini").line).substring(9)
$secpasswd = ConvertTo-SecureString $AdminPWD -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($userID, $secpasswd)
$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)
write-BuildLog "Make sure there are no installs underway"
do {
start-sleep 10
} until ((get-process "msiexec" -ea SilentlyContinue) -eq $Null)
write-BuildLog "Waiting two minutes for View services to settle"
Write-Host "You can start building CS2 at this stage"
start-sleep 120
function Get-MapEntry {
param([Parameter(Mandatory = $true)] $Key, [Parameter(Mandatory = $true)] $Value)
$update = New-Object VMware.Hv.MapEntry
$update.key = $key
$update.value = $value
return $update
}
# This script part modified from https://www.sddcmaster.com/2018/02/horizon-view-automation-with-powershell.html
Write-BuildLog "Add VC certificates to local certificate stores"
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
[System.Uri] $u = New-Object System.Uri($url)
[Net.ServicePoint] $sp = [Net.ServicePointManager]::FindServicePoint($u);
[System.Guid] $groupName = [System.Guid]::NewGuid()
[Net.HttpWebRequest] $req = [Net.WebRequest]::create($url)
$req.Method = "GET"
$req.Timeout = 600000 # = 10 minutes
$req.ConnectionGroupName = $groupName
[Net.HttpWebResponse] $result = $req.GetResponse()
$null = $sp.CloseConnectionGroup($groupName)
$outfilename = "Export.cer"
[System.Byte[]] $data = $sp.Certificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)
[System.IO.File]::WriteAllBytes($outfilename, $data)
$null = Import-Certificate -FilePath "Export.cer" -CertStoreLocation Cert:\LocalMachine\Root
$null = Import-Certificate -FilePath "Export.cer" -CertStoreLocation Cert:\LocalMachine\CA
$null = Import-Certificate -FilePath "Export.cer" -CertStoreLocation Cert:\LocalMachine\My
$null = Import-Certificate -FilePath "Export.cer" -CertStoreLocation Cert:\LocalMachine\AuthRoot
$null = Import-Certificate -FilePath "Export.cer" -CertStoreLocation Cert:\LocalMachine\TrustedDevices
Write-BuildLog "Connect to View"
Import-Module VMware.VimAutomation.HorizonView
$hvServer = Connect-HVServer -server localhost -credential $cred
$Global:hvServices = $hvServer.ExtensionData
Write-BuildLog "Add vCentre to View"
$vcService = New-Object VMware.Hv.VirtualCenterService
$certService = New-Object VMware.Hv.CertificateService
$vcSpecHelper = $vcService.getVirtualCenterSpecHelper()
$serverSpec = $vcSpecHelper.getDataObject().serverSpec
$serverSpec.serverName = $VCHost
$serverSpec.port = 443
$serverSpec.useSSL = $true
$serverSpec.userName = "administrator"
$vcPassword = New-Object VMware.Hv.SecureString
$enc = [system.Text.Encoding]::UTF8
$vcPassword.Utf8String = $enc.GetBytes($AdminPWD)
$serverSpec.password = $vcPassword
$serverSpec.serverType = $certService.getServerSpecHelper().SERVER_TYPE_VIRTUAL_CENTER
$certData = $certService.Certificate_Validate($hvServices, $serverSpec)
$certificateOverride = New-Object VMware.Hv.CertificateThumbprint
$certificateOverride.sslCertThumbprint = $certData.thumbprint.sslCertThumbprint
$certificateOverride.sslCertThumbprintAlgorithm = $certData.thumbprint.sslCertThumbprintAlgorithm
# Adding View Composer was a pain
$ViewComposerData = New-Object VMware.Hv.VirtualCenterViewComposerData
$ViewComposerData.viewComposerType = "LOCAL_TO_VC"
$ViewCompserverspec = New-Object VMware.Hv.ServerSpec
$ViewCompserverspec.port = 18443
$ViewCompserverspec.serverName = 'vc.lab.local'
$ViewCompserverspec.userName = 'administrator'
$ViewCompserverspec.password = $vcPassword
$ViewCompserverspec.serverType = 'VIEW_COMPOSER'
$ViewCompserverspec.useSSL = $True
$ViewComposerData.ServerSpec = $ViewCompserverspec
$compCertService = New-Object VMware.Hv.CertificateService
$compCertData = $compcertService.Certificate_Validate($hvServices, $ViewCompserverspec)
$compCertificateOverride = New-Object VMware.Hv.CertificateThumbprint
$compCertificateOverride.sslCertThumbprint = $compCertData.thumbprint.sslCertThumbprint
$compCertificateOverride.sslCertThumbprintAlgorithm = $compCertData.thumbprint.sslCertThumbprintAlgorithm
$ViewComposerData.CertificateOverride = $compCertificateOverride
$vcSpecHelper.getDataObject().ViewComposerData = $ViewComposerData
$vcSpecHelper.getDataObject().CertificateOverride = $certificateOverride
$vcId = $vcService.VirtualCenter_Create($hvServices, $vcSpecHelper.getDataObject())
Write-BuildLog "Setup View composer domain"
$spec = New-Object VMware.Hv.ViewComposerDomainAdministratorSpec
$spec.Base = New-Object VMware.Hv.ViewComposerDomainAdministratorBase
$spec.Base.Domain = 'lab.local'
$spec.Base.UserName = 'vi-admin'
$ADPassword = New-Object VMware.Hv.SecureString
$ADPassword.Utf8String = $enc.GetBytes("VMware1!")
$spec.Base.Password = $ADPassword
$spec.VirtualCenter = $global:DefaultVIServer.Id
#Write-BuildLog "Set Security Server pairing password"
#Since the type doesn't appear to be in the Powershell module we cannot add the pairing password
#$pairingData = New-Object VMware.Hv.SecurityServerPairingData
#$pairingPassword = New-Object VMware.Hv.SecureString
#$pairingPassword.Utf8String = $enc.GetBytes("VMware1!")
#$pairingData.pairingPassword = $pairingPassword
#$pairingData.timeoutMinutes = 1440
#$CS1 = ($hvServices.ConnectionServer.ConnectionServer_List())[0]
#$CS1.securityServerPairing = $pairingData
$icausername="vi-admin"
$icadomain = "lab.local"
$icadminPassword = New-Object VMware.Hv.SecureString
$enc = [system.Text.Encoding]::UTF8
$icadminPassword.Utf8String = $enc.GetBytes($AdminPWD)
$spec=new-object vmware.hv.InstantCloneEngineDomainAdministratorSpec
$spec.base=new-object vmware.hv.InstantCloneEngineDomainAdministratorBase
$spec.base.domain=(($hvServices.ADDomain.addomain_list() | where {$_.DnsName -eq $icadomain} | select-object -first 1).id)
$spec.base.username=$icausername
$spec.base.password=$icadminpassword
$ICADM = $hvServices.InstantCloneEngineDomainAdministrator.InstantCloneEngineDomainAdministrator_Create($spec)
Write-BuildLog "Setup View eventlog"
$updates = @()
$updates += Get-MapEntry -key "database.server" -value "dc.lab.local"
$updates += Get-MapEntry -key "database.type" -value "SQLSERVER"
$updates += Get-MapEntry -key "database.name" -value "ViewEvents"
$updates += Get-MapEntry -key "database.port" -value 1433
$updates += Get-MapEntry -key "database.userName" -value "VMview"
$updates += Get-MapEntry -key "database.password" -value $ADPassword
$updates += Get-MapEntry -key "database.tablePrefix" -value "Lab_"
$Events = $hvServices.EventDatabase.EventDatabase_Update($updates)
Disconnect-HVServer -server localhost -Force -Confirm:$false
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Config /f
if (([bool]($emailto -as [Net.Mail.MailAddress])) -and ($SmtpServer -ne "none")){
Write-BuildLog "Emailing log"
$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")
$mailmessage.Attachments.Add($attach)
$SMTPClient.Send($mailmessage)
$mailmessage.dispose()
$SMTPClient.dispose()
}
#read-host "Check VC was added"

View File

@ -1,10 +1,12 @@
@echo off
echo *************************
echo *
echo **
echo * Begining Build.cmd as %userdomain%\%username%
echo * Begining Build.cmd as %userdomain%\%username% >> c:\buildlog.txt
echo * Connect to build share
net use B: \\192.168.199.7\Build >> c:\buildlog.txt
type b:\automate\version.txt >> c:\buildlog.txt
echo * Connect to build share >> c:\buildlog.txt
if not exist B:\ net use B: \\192.168.199.7\Build
if not exist c:\temp\ md c:\temp
regedit -s b:\Automate\_Common\ExecuPol.reg
regedit -s b:\Automate\_Common\NoSCRNSave.reg
regedit -s B:\Automate\_Common\ExplorerView.reg
@ -13,7 +15,9 @@ REG ADD "HKCU\Environment" /V SEE_MASK_NOZONECHECKS /T REG_SZ /D 1 /F
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /V SEE_MASK_NOZONECHECKS /T REG_SZ /D 1 /F
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments " /V SaveZoneInformation /T REG_DWORD /D 1 /F
echo * Activate Windows >> c:\buildlog.txt
copy B:\automate\_Common\wasp.dll C:\windows\system32
cscript //B "%windir%\system32\slmgr.vbs" /ato
copy B:\Automate\validate.ps1 C:\
copy B:\Automate\PSFunctions.ps1 C:\
copy B:\Automate\%computername%\Build.ps1 c:\
echo * Starting PowerShell script for Phase 2 completion

View File

@ -5,6 +5,13 @@ if (Test-Path C:\PSFunctions.ps1) {
Read-Host "Press <Enter> to exit"
exit
}
$a = (Get-Host).UI.RawUI
$a.WindowTitle = "CS2 Build Automation"
$b = $a.WindowSize
$b.Height = $a.MaxWindowSize.Height - 1
$a.WindowSize = $b
Import-Module C:\windows\system32\WASP.dll
Select-Window -Title "CS2 Build Automation" | set-windowposition -left 75 -top 3
if (Test-Path "B:\Automate\automate.ini") {
Write-BuildLog "Determining automate.ini settings."
@ -17,13 +24,29 @@ if (Test-Path "B:\Automate\automate.ini") {
$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)
}
If (([System.Environment]::OSVersion.Version.Major -eq 6) -and ([System.Environment]::OSVersion.Version.Minor -ge 2)) {
if ((Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain -eq $False) {
Write-BuildLog "Joining domain"
B:\automate\_Common\Autologon administrator lab $AdminPWD
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Build /t REG_SZ /d "cmd /c c:\Build.cmd" /f
$password = $AdminPWD | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("administrator",$password)
$null = Add-Computer -DomainName "lab.local" -Credential $credential -restart
read-host "Wait for restart"
} else {
regedit /s b:\Automate\_Common\ExecuPol.reg
regedit -s b:\Automate\_Common\NoSCRNSave.reg
Write-BuildLog "Change default local administrator password"
net user administrator $AdminPWD
B:\automate\_Common\Autologon administrator lab $AdminPWD
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Build /f
}
If ((([System.Environment]::OSVersion.Version.Major *10) + [System.Environment]::OSVersion.Version.Minor) -ge 62) {
Write-BuildLog "Disabling autorun of ServerManager at logon."
Start-Process schtasks -ArgumentList ' /Change /TN "\Microsoft\Windows\Server Manager\ServerManager" /DISABLE' -Wait -Verb RunAs
Write-BuildLog "Disabling screen saver"
set-ItemProperty -path 'HKCU:\Control Panel\Desktop' -name ScreenSaveActive -value 0
Write-BuildLog "Install admin tools"
Add-WindowsFeature RSAT-Feature-Tools,RSAT-DHCP,RSAT-DNS-Server,RSAT-AD-AdminCenter
$null = Add-WindowsFeature RSAT-Feature-Tools,RSAT-DHCP,RSAT-DNS-Server,RSAT-AD-AdminCenter
Write-BuildLog "Enable remote management through firewall"
Netsh firewall set service RemoteAdmin
Netsh advfirewall set currentprofile settings remotemanagement enable
@ -35,42 +58,70 @@ if (Test-Path "C:\VMware-view*") {
If ($Files[$i].Name -like "VMware-view*") {$Installer = $Files[$i].FullName}
}
switch ($viewinstall) {
70 {
75 {
Write-BuildLog "Install View 7.5 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=2 ADAM_PRIMARY_NAME=cs1.lab.local VDM_IP_PROTOCOL_USAG=IPv4 HTMLACCESS=1"' -verb RunAs
if ([System.Environment]::OSVersion.Version.Major -ge 9) {
C:\Windows\Microsoft.NET\Framework64\v4.0.30319 \InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}else {
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
} 70 {
Write-BuildLog "Install View 7.0 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=2 ADAM_PRIMARY_NAME=cs1.lab.local"' -verb RunAs
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
if ([System.Environment]::OSVersion.Version.Major -ge 9) {
C:\Windows\Microsoft.NET\Framework64\v4.0.30319 \InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}else {
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
}
60 {
Write-BuildLog "Install View 6.0 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=2 ADAM_PRIMARY_NAME=cs1.lab.local"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
53{
Write-BuildLog "Install View 5.3 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=2 ADAM_PRIMARY_NAME=cs1.lab.local"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
52 {
Write-BuildLog "Install View 5.2 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=2 ADAM_PRIMARY_NAME=cs1.lab.local"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
51 {
Write-BuildLog "Install View 5.1 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=2 ADAM_PRIMARY_NAME=cs1.lab.local"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
50 {
Write-BuildLog "Install View 5.0 Connection Server"
Start-Process $Installer -wait -ArgumentList '/s /v"/qn VDM_SERVER_INSTANCE_TYPE=2 ADAM_PRIMARY_NAME=cs1.lab.local"'
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll" >> c:\buildLog.txt
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe "C:\Program Files\VMware\VMware View\Server\bin\PowershellServiceCmdlets.dll"
}
}
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Build /f
if (([bool]($emailto -as [Net.Mail.MailAddress])) -and ($SmtpServer -ne "none")){
Write-BuildLog "Emailing log"
$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")
$mailmessage.Attachments.Add($attach)
$SMTPClient.Send($mailmessage)
}
Exit
}
Write-BuildLog "Install Flash Player"
Start-Process msiexec -wait -ArgumentList " /i b:\Automate\_Common\install_flash_player_11_active_x.msi /qn"
browserAndFlash
Write-BuildLog "Setup Firewall"
netsh advfirewall firewall add rule name="All ICMP V4" dir=in action=allow protocol=icmpv4
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes
@ -80,32 +131,15 @@ route add 192.168.201.0 mask 255.255.255.0 192.168.199.254 -p
Write-BuildLog "Cleanup"
regedit /s b:\Automate\_Common\ExecuPol.reg
regedit -s b:\Automate\_Common\NoSCRNSave.reg
Write-BuildLog "Change default local administrator password"
net user administrator $AdminPWD
B:\automate\_Common\Autologon administrator CS2 $AdminPWD
Write-BuildLog "Copy Connection server install and setup recall"
$Files = get-childitem "b:\view$viewinstall"
for ($i=0; $i -lt $files.Count; $i++) {
If ($Files[$i].Name -like "VMware-viewconnectionserver*") {$Installer = $Files[$i].FullName}
}
copy $Installer C:\
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Build /t REG_SZ /d "cmd /c c:\Build.cmd" /f >> c:\buildlog.txt
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Build /t REG_SZ /d "cmd /c c:\Build.cmd" /f
Write-BuildLog "Install VMware Tools"
b:\VMTools\Setup64.exe /s /v "/qn"
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")
$mailmessage.Attachments.Add($attach)
$SMTPClient.Send($mailmessage)
}
Read-Host "Reboot?"

View File

@ -1,4 +1,6 @@
@echo off
echo * Begining Phase2.cmd as %userdomain%\%username%
echo * Begining Phase2.cmd as %userdomain%\%username% >> c:\buildlog.txt
net use B: \\192.168.199.7\Build
ver | find "6.1" > nul
if %ERRORLEVEL% == 0 goto ver_2K8
@ -6,36 +8,21 @@ ver | find "6.2" > nul
if %ERRORLEVEL% == 0 goto ver_2K12
ver | find "6.3" > nul
if %ERRORLEVEL% == 0 goto ver_2K12
ver | find "10.0" > nul
if %ERRORLEVEL% == 0 goto ver_2K16
Exit
:ver_2K12
If Exist C:\Windows\SYSVOL\* Goto ver_2K8
echo * Install DHCP and DNS
echo * Install DHCP and DNS >> c:\buildlog.txt
Dism /online /enable-feature /featurename:DHCPServer /quiet
Dism /online /enable-feature /featurename:DHCPServer-Tools /all /quiet
Dism /online /enable-feature /featurename:DNS-Server-Full-Role /quiet
Dism /online /enable-feature /featurename:DNS-Server-Tools /all /quiet
echo * Install AD DC Role
echo * Install AD DC Role >> c:\buildlog.txt
Dism /online /enable-feature /featurename:DirectoryServices-DomainController /all /quiet
Dism /online /enable-feature /featurename:DirectoryServices-AdministrativeCenter /all /quiet
Dism /online /enable-feature /featurename:ActiveDirectory-PowerShell /all /quiet
sc config dhcpserver start= auto
regedit -s B:\Automate\_Common\ExecuPol.reg
regedit -s B:\Automate\_Common\NoSCRNSave.reg
regedit -s B:\Automate\_Common\ExplorerView.reg
regedit -s b:\Automate\_Common\Nested.reg
echo * Promote to DC
echo * Promote to DC >> c:\buildlog.txt
copy \\192.168.199.7\Build\Automate\DC\dcpromo.ps1 c:\
powershell c:\dcpromo.ps1
pause
:ver_2K8
echo * Install services on Windows 2008
echo * Install services on Windows 2008 >> c:\buildlog.txt
Dism /online /enable-feature /featurename:DHCPServerCore >> c:\buildlog.txt
Dism /online /enable-feature /featurename:DNS-Server-Full-Role >> c:\buildlog.txt
sc config dhcpserver start= auto >> c:\buildlog.txt
:ver_2K12
:ver_2K16
echo **
echo * Connect to build share
echo * Connect to build share >> c:\buildlog.txt
net use B: \\192.168.199.7\Build
type B:\automate\version.txt >> C:\buildlog.txt
net use b: \\192.168.199.7\Build
echo **
echo * Copy PowerShell files
echo * Copy PowerShell files >> c:\buildlog.txt
@ -53,5 +40,4 @@ cscript //B "%windir%\system32\slmgr.vbs" /ato
echo * Starting PowerShell script for Phase 2 completion
echo * Starting PowerShell script for Phase 2 completion >> C:\buildlog.txt
powershell c:\Phase2.ps1
if exist C:\phase2.ps1 del c:\phase2.ps1
if exist c:\phase2.cmd del c:\phase2.cmd
exit

View File

@ -6,6 +6,31 @@ if (Test-Path C:\PSFunctions.ps1) {
exit
}
if((get-process "dcpromo" -ea SilentlyContinue) -ne $Null){
write-buildlog "DCPromo still in progress, closing"
exit
}
Try {
Get-ADDomainController -Discover -ea SilentlyContinue
} catch {
write-buildlog "Not yet a domain controller, DCPromo"
#Install-Windowsfeature AD-Domain-Services,DNS -IncludeManagementTools
$null = Add-WindowsFeature -name ad-domain-services -IncludeManagementTools
$safemodeadminpwd = ConvertTo-SecureString -String "VMware1!" -asplaintext -force
Write-buildlog "Install-ADDSForest"
$null = Install-ADDSForest -DomainName "lab.local" -ForestMode Win2008R2 -DomainMode Win2008R2 -SafeModeAdministratorPassword $safemodeadminpwd -Force
exit
}
write-buildlog "Starting Phase2.ps1"
$a = (Get-Host).UI.RawUI
$a.WindowTitle = "DC Build Automation"
$b = $a.WindowSize
$b.Height = $a.MaxWindowSize.Height - 1
$a.WindowSize = $b
Import-Module C:\windows\system32\WASP.dll
Select-Window -Title "DC Build Automation" | set-windowposition -left 75 -top 3
# Start DC configuration process
if (Test-Path B:\Automate\automate.ini) {
$KMSIP = "0.0.0.0"
@ -45,13 +70,12 @@ if (Test-Path B:\Automate\automate.ini) {
Write-BuildLog "Installing 7-zip."
try {
msiexec /qb /i B:\Automate\_Common\7z920-x64.msi
msiexec /qb /i B:\Automate\_Common\7z1805-x64.msi
Write-BuildLog "Installation of 7-zip completed."
}
catch {
Write-BuildLog "7-zip installation failed."
}
Write-BuildLog ""
if (Test-Path "b:\VMware-PowerCLI.exe") {
$PowCLIver = (Get-ChildItem B:\VMware-PowerCLI.exe).VersionInfo.ProductVersion.trim()
if ($PowCLIver -eq "5.0.0.3501") {$PowCLIver = "5.0.0-3501"}
@ -75,7 +99,6 @@ if (Test-Path "C:\Program Files\Tftpd64_SE\Tftpd64_SVC.exe") {
Write-BuildLog "Copying B:\Automate\DC\TFTP-Root\ contents to C:\TFTP-Root."
xcopy B:\Automate\DC\TFTP-Root\*.* C:\TFTP-Root\ /s /c /y /q
Write-BuildLog "Installation of TFTP completed."
Write-BuildLog ""
}
Write-BuildLog "Set root password for ESXi builds"
@ -99,6 +122,54 @@ $TempContent = Get-Content B:\Automate\Hosts\esx12-5.cfg |%{$_ -replace "VMware1
$TempContent | Set-Content B:\Automate\Hosts\esx12-5.cfg
Write-BuildLog "Checking for vSphere files..."
if (Test-Path "B:\ESXi67\*") {
if ((Test-Path "B:\ESXi67\*.iso") -and !(Test-Path "B:\ESXi67\BOOT.CFG") ){
Write-BuildLog "Extracting ESXi 6.7 installer from ISO."
. "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\ESXi67\ B:\ESXi67\*.iso >> C:\ExtractLog.txt
}
Write-BuildLog "ESXi 6.7 found; creating C:\TFTP-Root\ESXi67 and copying ESXi 67 boot files."
$null = $null = New-Item -Path C:\TFTP-Root\ESXi67 -ItemType Directory -Force -Confirm:$false
xcopy B:\ESXi67\*.* C:\TFTP-Root\ESXi67\ /s /c /y /q
Get-Content C:\TFTP-Root\ESXi67\BOOT.CFG | %{$_ -replace "/","/ESXi67/"} | Set-Content C:\TFTP-Root\ESXi67\Besx1-67.cfg
Add-Content C:\TFTP-Root\ESXi67\Besx1-67.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx1-5.cfg"
Get-Content C:\TFTP-Root\ESXi67\BOOT.CFG | %{$_ -replace "/","/ESXi67/"} | Set-Content C:\TFTP-Root\ESXi67\Besx2-67.cfg
Add-Content C:\TFTP-Root\ESXi67\Besx2-67.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx2-5.cfg"
Get-Content C:\TFTP-Root\ESXi67\BOOT.CFG | %{$_ -replace "/","/ESXi67/"} | Set-Content C:\TFTP-Root\ESXi67\Besx3-67.cfg
Add-Content C:\TFTP-Root\ESXi67\Besx3-67.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx3-5.cfg"
Get-Content C:\TFTP-Root\ESXi67\BOOT.CFG | %{$_ -replace "/","/ESXi67/"} | Set-Content C:\TFTP-Root\ESXi67\Besx4-67.cfg
Add-Content C:\TFTP-Root\ESXi67\Besx4-67.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx4-5.cfg"
Get-Content C:\TFTP-Root\ESXi67\BOOT.CFG | %{$_ -replace "/","/ESXi67/"} | Set-Content C:\TFTP-Root\ESXi67\BOOTM.CFG
powershell C:\PXEMenuConfig.ps1 ESXi67
Write-BuildLog "ESXi 6.7 added to TFTP and PXE menu."
$esxi67 = $true
} else {
$esxi67 = $false
}
if (Test-Path "B:\ESXi65\*") {
if ((Test-Path "B:\ESXi65\*.iso") -and !(Test-Path "B:\ESXi65\BOOT.CFG") ){
Write-BuildLog "Extracting ESXi 6.5 installer from ISO."
. "C:\Program Files\7-Zip\7z.exe" x -r -y -aoa -oB:\ESXi65\ B:\ESXi65\*.iso >> C:\ExtractLog.txt
}
Write-BuildLog "ESXi 6.5 found; creating C:\TFTP-Root\ESXi65 and copying ESXi 65 boot files."
$null = $null = New-Item -Path C:\TFTP-Root\ESXi65 -ItemType Directory -Force -Confirm:$false
xcopy B:\ESXi65\*.* C:\TFTP-Root\ESXi65\ /s /c /y /q
Get-Content C:\TFTP-Root\ESXi65\BOOT.CFG | %{$_ -replace "/","/ESXi65/"} | Set-Content C:\TFTP-Root\ESXi65\Besx1-65.cfg
Add-Content C:\TFTP-Root\ESXi65\Besx1-65.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx1-5.cfg"
Get-Content C:\TFTP-Root\ESXi65\BOOT.CFG | %{$_ -replace "/","/ESXi65/"} | Set-Content C:\TFTP-Root\ESXi65\Besx2-65.cfg
Add-Content C:\TFTP-Root\ESXi65\Besx2-65.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx2-5.cfg"
Get-Content C:\TFTP-Root\ESXi65\BOOT.CFG | %{$_ -replace "/","/ESXi65/"} | Set-Content C:\TFTP-Root\ESXi65\Besx3-65.cfg
Add-Content C:\TFTP-Root\ESXi65\Besx3-65.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx3-5.cfg"
Get-Content C:\TFTP-Root\ESXi65\BOOT.CFG | %{$_ -replace "/","/ESXi65/"} | Set-Content C:\TFTP-Root\ESXi65\Besx4-65.cfg
Add-Content C:\TFTP-Root\ESXi65\Besx4-65.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx4-5.cfg"
Get-Content C:\TFTP-Root\ESXi65\BOOT.CFG | %{$_ -replace "/","/ESXi65/"} | Set-Content C:\TFTP-Root\ESXi65\BOOTM.CFG
powershell C:\PXEMenuConfig.ps1 ESXi65
Write-BuildLog "ESXi 6.5 added to TFTP and PXE menu."
$esxi65 = $true
} else {
$esxi65 = $false
}
if (Test-Path "B:\ESXi60\*") {
if ((Test-Path "B:\ESXi60\*.iso") -and !(Test-Path "B:\ESXi60\BOOT.CFG") ){
Write-BuildLog "Extracting ESXi 6.0 installer from ISO."
@ -115,10 +186,9 @@ if (Test-Path "B:\ESXi60\*") {
Add-Content C:\TFTP-Root\ESXi60\Besx3-60.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx3-5.cfg"
Get-Content C:\TFTP-Root\ESXi60\BOOT.CFG | %{$_ -replace "/","/ESXi60/"} | Set-Content C:\TFTP-Root\ESXi60\Besx4-60.cfg
Add-Content C:\TFTP-Root\ESXi60\\Besx4-60.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx4-5.cfg"
Get-Content C:\TFTP-Root\ESXi60\BOOT.CFG | %{$_ -replace "/","/ESXi60/"} | Set-Content C:\TFTP-Root\ESXi60\BOOT.CFG
Get-Content C:\TFTP-Root\ESXi60\BOOT.CFG | %{$_ -replace "/","/ESXi60/"} | Set-Content C:\TFTP-Root\ESXi60\BOOTM.CFG
powershell C:\PXEMenuConfig.ps1 ESXi60
Write-BuildLog "ESXi 6.0 added to TFTP and PXE menu."
Write-BuildLog ""
$esxi60 = $true
} else {
$esxi60 = $false
@ -140,10 +210,9 @@ if (Test-Path "B:\ESXi55\*") {
Add-Content C:\TFTP-Root\ESXi55\Besx3-55.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx3-5.cfg"
Get-Content C:\TFTP-Root\ESXi55\BOOT.CFG | %{$_ -replace "/","/ESXi55/"} | Set-Content C:\TFTP-Root\ESXi55\Besx4-55.cfg
Add-Content C:\TFTP-Root\ESXi55\\Besx4-55.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx4-5.cfg"
Get-Content C:\TFTP-Root\ESXi55\BOOT.CFG | %{$_ -replace "/","/ESXi55/"} | Set-Content C:\TFTP-Root\ESXi55\BOOT.CFG
Get-Content C:\TFTP-Root\ESXi55\BOOT.CFG | %{$_ -replace "/","/ESXi55/"} | Set-Content C:\TFTP-Root\ESXi55\BOOTM.CFG
powershell C:\PXEMenuConfig.ps1 ESXi55
Write-BuildLog "ESXi 5.5 added to TFTP and PXE menu."
Write-BuildLog ""
$esxi55 = $true
} else {
$esxi55 = $false
@ -165,10 +234,9 @@ if (Test-Path "B:\ESXi51\*") {
Add-Content C:\TFTP-Root\ESXi51\Besx3-5.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx3-5.cfg"
Get-Content C:\TFTP-Root\ESXi51\BOOT.CFG | %{$_ -replace "/","/ESXi51/"} | Set-Content C:\TFTP-Root\ESXi51\Besx4-5.cfg
Add-Content C:\TFTP-Root\ESXi51\Besx4-5.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx4-5.cfg"
Get-Content C:\TFTP-Root\ESXi51\BOOT.CFG | %{$_ -replace "/","/ESXi51/"} | Set-Content C:\TFTP-Root\ESXi51\BOOT.CFG
Get-Content C:\TFTP-Root\ESXi51\BOOT.CFG | %{$_ -replace "/","/ESXi51/"} | Set-Content C:\TFTP-Root\ESXi51\BOOTM.CFG
powershell C:\PXEMenuConfig.ps1 ESXi51
Write-BuildLog "ESXi 5.1 added to TFTP and PXE menu."
Write-BuildLog ""
$esxi51 = $true
} else {
$esxi51 = $false
@ -190,10 +258,9 @@ if (Test-Path "B:\ESXi50\*") {
Add-Content C:\TFTP-Root\ESXi50\Besx3-5.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx3-5.cfg"
Get-Content C:\TFTP-Root\ESXi50\BOOT.CFG | %{$_ -replace "/","/ESXi50/"} | Set-Content C:\TFTP-Root\ESXi50\Besx4-5.cfg
Add-Content C:\TFTP-Root\ESXi50\Besx4-5.cfg "kernelopt=ks=nfs://192.168.199.7/mnt/LABVOL/Build/Automate/Hosts/esx4-5.cfg"
Get-Content C:\TFTP-Root\ESXi50\BOOT.CFG | %{$_ -replace "/","/ESXi50/"} | Set-Content C:\TFTP-Root\ESXi50\BOOT.CFG
Get-Content C:\TFTP-Root\ESXi50\BOOT.CFG | %{$_ -replace "/","/ESXi50/"} | Set-Content C:\TFTP-Root\ESXi50\BOOTM.CFG
powershell C:\PXEMenuConfig.ps1 ESXi50
Write-BuildLog "ESXi 5.0 added to TFTP and PXE menu."
Write-BuildLog ""
$esxi50 = $true
} else {
$esxi50 = $false
@ -215,7 +282,6 @@ if (Test-Path "B:\ESXi41\*") {
xcopy B:\ESXi41\mboot.c32 C:\TFTP-Root\ESXi41 /s /c /y /q
powershell C:\PXEMenuConfig.ps1 ESXi41
Write-BuildLog "ESXi 4.1 added to TFTP and PXE menu."
Write-BuildLog ""
$esxi41 = $true
} else {
$esxi41 = $false
@ -232,13 +298,12 @@ if (Test-Path "B:\ESX41\*") {
xcopy B:\ESX41\isolinux\initrd.img C:\TFTP-Root\ESX41 /s /c /y /q
powershell C:\PXEMenuConfig.ps1 ESX41
Write-BuildLog "ESX 4.1 added to TFTP and PXE menu."
Write-BuildLog ""
$esx41 = $true
} else {
$esx41 = $false
}
if (!($esx41 -or $esxi41 -or $esxi50 -or $esxi51 -or $esxi55 -or $esxi60)) {
if (!($esx41 -or $esxi41 -or $esxi50 -or $esxi51 -or $esxi55 -or $esxi60 -or $esxi65 -or $esxi67)) {
Write-BuildLog "No ESX or ESXi files found."
Write-BuildLog "Is the NAS VM running? If so, make sure the Build share is available and populated."
Write-BuildLog "Restart this machine when Build share is available; build will proceed after restart."
@ -254,16 +319,39 @@ if (Test-Path "B:\gParted\*") {
LABEL gParted
MENU LABEL gParted utility