Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $logfiledate = get-date -format "yyyy-MM-dd %h-m-ss"
- $logfile = "C:\Admin\Logs\Deployment Transcript $logfiledate.txt"
- start-transcript -path $logfile
- if ( (Get-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null )
- {
- Add-PsSnapin "VMware.VimAutomation.Core"
- }
- Write-host Connecting to server -foregroundcolor "magenta"
- connect-viserver blah -ErrorAction Stop
- #Generate random password
- Add-Type -Assembly System.Web
- $length = 12
- $numberOfNonAlphanumericCharacters = 4
- $password = [Web.Security.Membership]::GeneratePassword($length,$numberOfNonAlphanumericCharacters)
- #Set VNC in the vmx
- Function Set_VMX
- {
- #Generating VNC port
- [int]$vncport = get-content vncport.txt
- $vncport++
- $vncport | Out-file VNCPort.txt
- Get-VM -name $nameselection | Get-AdvancedSetting -name "RemoteDisplay.vnc.password" | Set-AdvancedSetting -Value $password -confirm:$false
- Get-VM -name $nameselection | Get-AdvancedSetting -name "RemoteDisplay.vnc.port" | Set-AdvancedSetting -Value $vncport -confirm:$false
- }
- #Email configuration details
- Function Email_deets
- {
- $uuid = get-vm -name $nameselection | %{(Get-View $_.Id).config.uuid}
- $guid = get-vm -name $nameselection | Get-View | select -ExpandProperty MoRef
- $bundleplan = $bundleselection.Plan
- [int]$vncportout = get-content vncport.txt
- Send-MailMessage -smtpserver blah -to "blah" -from "blah" -subject "[iseek-track #$ticketselection] Configuration details for VM: $nameselection" -attachment $logfile -body "Administrator username: Administrator
- Password: $password
- Bundle: $bundleplan
- Template: $osplan
- OSCode: $oscode
- BYOL expiry: $BYOLselection
- Short backup: $shortbackup
- Long backup: $longbackup
- Datastore: $datastoreselection
- Port group: $portgroupselection
- I.P: $ipselection
- Subnet: $subselection
- Gateway: $gateselection
- VNC Port: $vncportout
- VNC Password: $password
- UUID: $uuid
- GUID: $guid
- "
- }
- #Ticket #
- Function Enter_Ticket
- {
- Clear
- [int]$tans = Read-Host 'Enter the ticket #'
- $ticketselection = $tans
- if (($ticketselection -eq $null) -or ($tans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine the ticket #. Please retry..."
- Start-Sleep -s 1
- Enter_Ticket
- }
- else
- {
- #Goto Name
- Select_Name
- }
- }
- #Name the VM
- Function Select_Name
- {
- [string]$nans = Read-Host 'Enter the name you want to assign to the VM'
- $nameselection = $nans
- if (($nameselection -eq $null) -or ($nans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine the name you want. Please retry..."
- Start-Sleep -s 1
- Select_Name
- }
- else
- {
- #Go to Organisation
- Select_OrgName
- }
- }
- #Organisation name
- Function Select_OrgName
- {
- [string]$onans = Read-Host 'Enter the Organisation name you want to assign to the VM'
- $orgnameselection = $onans
- if (($orgnameselection -eq $null) -or ($onans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine the name you want. Please retry..."
- Start-Sleep -s 1
- Select_Name
- }
- else
- {
- #Go to I.P
- Select_IP
- }
- }
- #I.P
- Function Select_IP
- {
- [string]$ipans = Read-Host 'Enter the I.P you want to assign to the VM'
- $ipselection = $ipans
- if (($ipselection -eq $null) -or ($ipans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine the I.P you want. Please retry..."
- Start-Sleep -s 1
- Select_Name
- }
- else
- {
- #Go to subnet
- Select_Subnet
- }
- }
- #subnet
- Function Select_Subnet
- {
- [string]$subans = Read-Host 'Enter the subnet you want to assign to the VM'
- $subselection = $subans
- if (($subselection -eq $null) -or ($subans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine the subnet you want. Please retry..."
- Start-Sleep -s 1
- Select_Name
- }
- else
- {
- #Go to gateway
- Select_Gateway
- }
- }
- #gateway
- Function Select_Gateway
- {
- [string]$gateans = Read-Host 'Enter the gateway you want to assign to the VM'
- $gateselection = $gateans
- if (($gateselection -eq $null) -or ($gateans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine the gateway you want. Please retry..."
- Start-Sleep -s 1
- Select_Name
- }
- else
- {
- #Go to bundle
- Select_Bundle
- }
- }
- #Bundle menu
- Function Select_Bundle
- {
- $bundle = import-csv bundles.csv
- Write-host Select your bundle
- $bundlemenu = @{}
- for ($i=1;$i -le $bundle.count; $i++) {
- Write-Host "$i. $($bundle[$i-1])" -foregroundcolor "green"
- $bundlemenu.Add($i,($bundle[$i-1]))
- }
- [int]$bundleans = Read-Host 'Enter bundle selection'
- $bundleselection = $bundlemenu.Item($bundleans)
- if (($bundleans -gt $bundle.count) -or ($bundleselection -eq $null) -or ($bundleans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine which bundle you want. Please retry..."
- Start-Sleep -s 1
- Select_Bundle
- }
- else
- {
- #Go to OS plan
- Select_OSPlan
- }
- }
- #Select OS Plan
- Function Select_OSPlan
- {
- Write-host Please select the OS plan
- [int]$osselection = 0
- while ( $osselection -lt 1 -or $osselection -gt 18 ){
- Write-host "1. Windows Server 2008 R2 Standard" -foregroundcolor "green"
- Write-host "2. Windows Server 2008 R2 Standard - BYOL" -foregroundcolor "green"
- Write-host "3. Windows Server 2012 Standard" -foregroundcolor "green"
- Write-host "4. Windows Server 2012 Standard - BYOL" -foregroundcolor "green"
- Write-host "5. Windows Server 2012 R2 Standard" -foregroundcolor "green"
- Write-host "6. Windows Server 2012 R2 Standard - BYOL" -foregroundcolor "green"
- Write-host "7. Windows Server 2008 R2 Standard + SQL WEB" -foregroundcolor "green"
- Write-host "8. Windows Server 2008 R2 Standard + SQL WEB - BYOL" -foregroundcolor "green"
- Write-host "9. Windows Server 2012 Standard + SQL WEB" -foregroundcolor "green"
- Write-host "10. Windows Server 2012 Standard + SQL WEB - BYOL" -foregroundcolor "green"
- Write-host "11. Windows Server 2012 R2 Standard + SQL WEB" -foregroundcolor "green"
- Write-host "12. Windows Server 2012 R2 Standard + SQL WEB - BYOL" -foregroundcolor "green"
- Write-host "13. Windows Server 2008 R2 Standard + SQL Standard" -foregroundcolor "green"
- Write-host "14. Windows Server 2008 R2 Standard + SQL Standard - BYOL" -foregroundcolor "green"
- Write-host "15. Windows Server 2012 Standard + SQL Standard" -foregroundcolor "green"
- Write-host "16. Windows Server 2012 Standard + SQL Standard - BYOL" -foregroundcolor "green"
- Write-host "17. Windows Server 2012 R2 Standard + SQL Standard" -foregroundcolor "green"
- Write-host "18. Windows Server 2012 R2 Standard + SQL Standard - BYOL" -foregroundcolor "green"
- [Int]$osselection = read-host "Please enter an option" }
- Switch( $osselection ){
- 1{ $templateselection = "Server 2008 R2 Standard Template"
- $osplan = "Windows Server 2008 R2 Standard"
- $oscustselection = "Windows - Win2K8 Licensed"
- $oscode = "W2008R2-S"
- }
- 2{ $templateselection = "Server 2008 R2 Standard Template"
- $osplan = "Windows Server 2008 R2 Standard - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2008R2-S-BYOL"
- }
- 3{ $templateselection = "Server 2012 Standard Template"
- $osplan = "Windows Server 2012 Standard"
- $oscustselection = "Windows - 2012 Licensed"
- $oscode = "W2012-S"
- }
- 4{ $templateselection = "Server 2012 Standard Template"
- $osplan = "Windows Server 2012 Standard - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2012-S-BYOL"
- }
- 5{ $templateselection = "Server 2012 R2 Standard Template"
- $osplan = "Windows Server 2012 R2 Standard"
- $oscustselection = "Windows - 2012 R2 Licensed"
- $oscode = "W2012R2-S"
- }
- 6{ $templateselection = "Server 2012 R2 Standard Template"
- $osplan = "Windows Server 2012 R2 Standard - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2012R2-S-BYOL"
- }
- 7{ $templateselection = "Server 2008 R2 Standard Template"
- $osplan = "Windows Server 2008 R2 Standard + SQL WEB"
- $oscustselection = "Windows - Win2K8 Licensed"
- $oscode = "W2008R2-S-WEB"
- $sql = "SQL Web"
- }
- 8{ $templateselection = "Server 2008 R2 Standard Template"
- $osplan = "Windows Server 2008 R2 Standard + SQL WEB - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2008R2-S-WEB-BYOL"
- $sql = "SQL Web"
- }
- 9{ $templateselection = "Server 2012 Standard Template"
- $osplan = "Windows Server 2012 Standard + SQL WEB"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2012-S-WEB"
- $sql = "SQL Web"
- }
- 10{ $templateselection = "Server 2012 Standard Template"
- $osplan = "Windows Server 2012 Standard + SQL WEB - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2012-S-WEB-BYOL"
- $sql = "SQL Web"
- }
- 11{ $templateselection = "Server 2012 R2 Standard Template"
- $osplan = "Windows Server 2012 R2 Standard + SQL WEB"
- $oscustselection = "Windows - 2012 R2 Licensed"
- $oscode = "W2012R2-S-WEB"
- $sql = "SQL Web"
- }
- 12{ $templateselection = "Server 2012 R2 Standard Template"
- $osplan = "Windows Server 2012 R2 Standard + SQL - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2012R2-S-WEB-BYOL"
- $sql = "SQL Standard"
- }
- 13{ $templateselection = "Server 2008 R2 Standard Template"
- $osplan = "Windows Server 2008 R2 Standard + SQL Standard"
- $oscustselection = "Windows - Win2K8 Licensed"
- $oscode = "W2008R2-S-STD"
- $sql = "SQL Standard"
- }
- 14{ $templateselection = "Server 2008 R2 Standard Template"
- $osplan = "Windows Server 2008 R2 Standard + SQL Standard - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2008R2-S-STD-BYOL"
- $sql = "SQL Standard"
- }
- 15{ $templateselection = "Server 2012 Standard Template"
- $osplan = "Windows Server 2012 Standard + SQL Standard"
- $oscustselection = "Windows - 2012 Licensed"
- $oscode = "W2012-S-STD"
- $sql = "SQL Standard"
- }
- 16{ $templateselection = "Server 2012 Standard Template"
- $osplan = "Windows Server 2012 Standard + SQL Standard - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2012-S-STD-BYOL"
- $sql = "SQL Standard"
- }
- 17{ $templateselection = "Server 2012 R2 Standard Template"
- $osplan = "Windows Server 2012 R2 Standard + SQL Standard"
- $oscustselection = "Windows - 2012 R2 Licensed"
- $oscode = "W2012R2-S-STD"
- $sql = "SQL Standard"
- }
- 18{ $templateselection = "Server 2012 R2 Standard Template"
- $osplan = "Windows Server 2012 R2 Standard + SQL Standard - BYOL"
- $oscustselection = "Windows - Unlicensed"
- $oscode = "W2012R2-S-STD-BYOL"
- $sql = "SQL Standard"
- }
- }
- #Go to BYOL
- Enter_BYOLExpiry
- }
- #BYOL license expiry
- Function Enter_BYOLExpiry
- {
- if ($oscode -like "*BYOL*")
- {
- [string]$BYOLans = Read-Host 'Enter the expiry date for the BYOL license agreement'
- $BYOLselection = $BYOLans
- Select_Cluster
- }
- else
- {
- #Go to cluster
- $BYOLselection = "Not needed"
- Select_Cluster
- }
- }
- #Cluster menu
- Function Select_Cluster
- {
- Write-host Select your cluster
- $esxcluster = get-cluster
- $esxclustermenu = @{}
- for ($i=1;$i -le $esxcluster.count; $i++) {
- Write-Host "$i. $($esxcluster[$i-1])" -foregroundcolor "green"
- $esxclustermenu.Add($i,($esxcluster[$i-1]))
- }
- [int]$cans = Read-Host 'Enter cluster selection'
- $esxclusterselection = $esxclustermenu.Item($cans)
- if (($cans -gt $esxcluster.count) -or ($esxclusterselection -eq $null) -or ($cans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine which ESX Cluster you want. Please retry..."
- Start-Sleep -s 1
- Select_Cluster
- }
- else
- {
- #Go to select host menu
- Select_Host
- }
- }
- #Host menu
- Function Select_Host
- {
- Write-host Select your host
- $esxhost = get-vmhost -location "$esxclusterselection"
- $hostmenu = @{}
- for ($i=1;$i -le $esxhost.count; $i++) {
- Write-Host "$i. $($esxhost[$i-1]) | memory used GB: $($esxhost.MemoryUsageGB[$i-1]) " -foregroundcolor "green"
- $hostmenu.Add($i,($esxhost[$i-1]))
- }
- [int]$hans = Read-Host 'Enter host selection'
- $hostselection = $hostmenu.Item($hans)
- if (($hans -gt $esxhost.count) -or ($hostselection -eq $null) -or ($hans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine which ESX host you want. Please retry..."
- Start-Sleep -s 1
- Select_Host
- }
- else
- {
- #Go to select Resource menu
- Select_Resource
- }
- }
- #Select resource pool
- Function Select_Resource
- {
- Write-host Select your resource pool
- $resourcepool = get-cluster $esxclusterselection | get-resourcepool
- $resourcemenu = @{}
- for ($i=1;$i -le $resourcepool.count; $i++) {
- Write-Host "$i. $($resourcepool[$i-1])" -foregroundcolor "green"
- $resourcemenu.Add($i,($resourcepool[$i-1]))
- }
- [int]$resans = Read-Host 'Enter resource pool selection'
- $resourceselection = $resourcemenu.Item($resans)
- if (($resans -gt $resourcepool.count) -or ($resourceselection -eq $null) -or ($resans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine which resource pool you want. Please retry..."
- Start-Sleep -s 1
- Select_Host
- }
- else
- {
- #Go to select Datastore menu
- Select_Datastore
- }
- }
- #Datastore menu
- Function Select_Datastore
- {
- Write-host Select your datastore
- $esxdatastore = get-datastore -vmhost $hostselection
- $datastoremenu = @{}
- for ($i=1;$i -le $esxdatastore.count; $i++) {
- Write-Host "$i. $($esxdatastore[$i-1])" -foregroundcolor "green"
- $datastoremenu.Add($i,($esxdatastore[$i-1]))
- }
- [int]$dans = Read-Host 'Enter datastore selection'
- $datastoreselection = $datastoremenu.Item($dans)
- if (($dans -gt $esxdatastore.count) -or ($datastoreselection -eq $null) -or ($dans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine which datastore you want. Please retry..."
- Start-Sleep -s 1
- Select_Datastore
- }
- else
- {
- #Go to select VD Switch menu
- Select_VDSwitch
- }
- }
- #VD Switch menu
- Function Select_VDSwitch
- {
- Write-host Select your VD Switch
- $esxswitch = get-vdswitch
- $switchmenu = @{}
- for ($i=1;$i -le $esxswitch.count; $i++) {
- Write-Host "$i. $($esxswitch[$i-1])" -foregroundcolor "green"
- $switchmenu.Add($i,($esxswitch[$i-1]))
- }
- [int]$vdsans = Read-Host 'Enter VD Switch selection'
- $switchselection = $switchmenu.Item($vdsans)
- if (($vdsans -gt $esxswitch.count) -or ($switchselection -eq $null) -or ($vdsans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine which virtual switch you want. Please retry..."
- Start-Sleep -s 1
- Select_VDSwitch
- }
- else
- {
- #Go to select Port group menu
- Select_Portgroup
- }
- }
- #Expand guest HDD
- Function Expand_GuestHDD
- {
- $time = 600 # seconds, use you actual time in here
- foreach($i in (1..$time)) {
- $percentage = $i / $time
- $remaining = New-TimeSpan -Seconds ($time - $i)
- $message = "{0:p0} complete, remaining time {1}" -f $percentage, $remaining
- Write-Progress -Activity $message -status "Sysprep is doing it's stuff..." -PercentComplete ($percentage * 100)
- Start-Sleep 1
- }
- Write-host Expanding guest primary partition -foregroundcolor "red"
- Get-HardDisk -vm $nameselection | Set-HardDisk -CapacityGB $bundleselection.Storage -ResizeGuestPartition -GuestUser Administrator -GuestPassword $password -confirm:$false
- }
- #Port group menu
- Function Select_Portgroup
- {
- Write-host Select your port group
- $esxportgroup = Get-VirtualPortGroup -VirtualSwitch $switchselection
- $portgroupmenu = @{}
- for ($i=1;$i -le $esxportgroup.count; $i++) {
- Write-Host "$i. $($esxportgroup[$i-1])" -foregroundcolor "green"
- $portgroupmenu.Add($i,($esxportgroup[$i-1]))
- }
- [int]$pgsans = Read-Host 'Enter port group selection'
- $portgroupselection = $portgroupmenu.Item($pgsans)
- if (($pgsans -gt $esxportgroup.count) -or ($portgroupselection -eq $null) -or ($pgsans -eq 0))
- {
- Write-Host -ForegroundColor Red "Couldn't determine which port group you want. Please retry..."
- Start-Sleep -s 1
- Select_Portgroup
- }
- else
- {
- #Go to select short backup
- Select_ShortBackups
- }
- }
- #Select SQL
- Function Select_SQL
- {
- if ($sql -eq "SQL Standard")
- {
- Write-host Mounting SQL 2008 R2 Standard CD -foregroundcolor "red"
- Get-CDDrive -VM $nameselection | Set-CDDrive -ISOpath "[ldr-ds001-7500] Software/en_sql_server_2008_r2_standard_x86_x64_ia64_dvd_521546.iso" -Connected $true -startconnected $true -confirm:$false
- Set_Annotations
- }
- elseif ($sql -eq "SQL Web")
- {
- Write-host Mounting SQL 2008 R2 Web CD -foregroundcolor "red"
- Get-CDDrive -VM $nameselection | Set-CDDrive -ISOpath "[ldr-ds001-7500] Software/en_sql_server_2008_r2_web_x86_x64_ia64_dvd_522515.iso" -Connected $true -startconnected $true -confirm:$false
- Set_Annotations
- }
- else
- {
- Set_Annotations
- }
- }
- #Short backups
- Function Select_ShortBackups
- {
- Write-host Please the short backup plan
- [int]$sbackupselection = 0
- while ( $sbackupselection -lt 1 -or $sbackupselection -gt 5 ){
- Write-host "1. EB-1W" -foregroundcolor "green"
- Write-host "2. EB-2W" -foregroundcolor "green"
- Write-host "3. EB-1M" -foregroundcolor "green"
- Write-host "4. EB-3M" -foregroundcolor "green"
- Write-host "5. EB-6M" -foregroundcolor "green"
- Write-host "5. EB-1Y" -foregroundcolor "green"
- [Int]$sbackupselection = read-host "Please enter an option" }
- Switch( $sbackupselection ){
- 1{ $vmfolder = "vm"
- $shortbackup = "EB-1W"
- }
- 2{ $vmfolder = "EB-2W"
- $shortbackup = "EB-2W"
- }
- 3{ $vmfolder = "EB-1M"
- $shortbackup = "EB-1M"
- }
- 4{ $vmfolder = "EB-3M"
- $shortbackup = "EB-3M"
- }
- 5{ $vmfolder = "EB-6M"
- $shortbackup = "EB-6M"
- }
- 6{ $vmfolder = "EB-1Y"
- $shortbackup = "EB-1Y"
- }
- }
- #Goto Select_LongBackups
- Select_LongBackups
- }
- #Long backups
- Function Select_LongBackups
- {
- if ($shortbackup -ne "EB-1W") {
- Confirm_Details
- }
- else {
- Write-host Please the long backup plan
- [int]$lbackupselection = 0
- while ( $lbackupselection -lt 1 -or $lbackupselection -gt 5 ){
- Write-host "1. None" -foregroundcolor "green"
- Write-host "2. HFB-1W" -foregroundcolor "green"
- Write-host "3. HFB-2W" -foregroundcolor "green"
- Write-host "4. HFB-1M" -foregroundcolor "green"
- [Int]$lbackupselection = read-host "Please enter an option" }
- Switch( $lbackupselection ){
- 1{ "Write-host No long backup plans selected"
- $longbackup = "None"
- }
- 2{ $vmfolder = "HFB-1W"
- $longbackup = "HFB-1W"
- }
- 3{ $vmfolder = "HFB-2W"
- $longbackup = "HFB-2W"
- }
- 4{ $vmfolder = "HFB-1M"
- $longbackup = "HFB-1M"
- }
- }
- }
- #Goto Confirm_Details
- Confirm_Details
- }
- #>
- #Confirm details
- Function Confirm_Details
- {
- $bundleplan = $bundleselection.Plan
- clear
- Write-host "Cluster: $esxclusterselection"
- Write-host "Host: $hostselection"
- Write-host "Resource pool: $resourceselection"
- Write-host "Bundle: $bundleplan"
- Write-host "OS Plan: $osplan"
- Write-host "Short Backup: $shortbackup"
- Write-host "Long Backup: $longbackup"
- Write-host "BYOL expiry: $BYOLselection"
- Write-host "Customisation image: $oscustselection"
- Write-host "Datastore: $datastoreselection"
- Write-host "Port group: $portgroupselection"
- Write-host "I.P: $ipselection"
- Write-host "Subnet: $subselection"
- Write-host "Gateway: $gateselection"
- Write-host "Confirm the above inputs are correct. If they aren't select NO and you will be sent back to the start of the script to start again" -foregroundcolor "red"
- [int]$confirmselection = 0
- while ( $confirmselection -lt 1 -or $confirmselection -gt 2 ){
- Write-host "1. Yes the above is correct" -foregroundcolor "green"
- Write-host "2. No something in the above is wrong" -foregroundcolor "green"
- [Int]$confirmselection = read-host "Please enter an option" }
- Switch( $confirmselection ){
- 1{ $date = get-date
- Build_VM
- }
- 2{ Enter_Ticket }
- }
- }
- #Set annotations
- Function Set_Annotations
- {
- Write-host Setting metadata VM -foregroundcolor "red"
- Set-Annotation -Entity $nameselection -customattribute guestPlan -Value $bundleselection.Plan
- Set-Annotation -Entity $nameselection -customattribute backupsShort -Value $shortbackup
- Set-Annotation -Entity $nameselection -customattribute backupsLong -Value $longbackup
- Set-Annotation -Entity $nameselection -customattribute createdDate -Value $date
- Set-Annotation -Entity $nameselection -customattribute osPlan -Value $oscode
- Set-Annotation -Entity $nameselection -customattribute byolExpiration -Value $BYOLselection
- Stop-Transcript
- Email_Deets
- }
- #Build VM
- Function Build_VM
- {
- Write-host Removing any old non-persistant customization specs -foregroundcolor "red"
- #Get-OSCustomizationSpec -type nonpersistent | Remove-OSCustomizationSpec -confirm:$false
- Write-host Creating a clone of the original customisation spec -foregroundcolor "red"
- New-OSCustomizationSpec -Name $nameselection -OSCustomizationSpec $oscustselection -type NonPersistent
- Write-host Updating the cloned customisation spec with new VM specific settings -foregroundcolor "red"
- Set-OSCustomizationSpec -OSCustomizationSpec $nameselection -adminpassword $password -OrgName $orgnameselection -fullname $nameselection
- Get-OSCustomizationSpec -name $nameselection | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IPMode UseStaticIP -IpAddress $ipselection -subnetmask $subselection -DefaultGateway $gateselection -DNS 8.8.8.8 -Confirm:$false
- Write-host Starting to build the VM -foregroundcolor "red"
- new-vm -name $nameselection -vmhost $hostelection -location $vmfolder -resourcepool $resourceselection -template $templateselection -datastore $datastoreselection -OSCustomizationSpec $nameselection
- Write-host Configuring the VM CPU and memory based on the bundle selection -foregroundcolor "red"
- Set-VM -vm $nameselection -MemoryGB $bundleselection.Mem -numcpu $bundleselection.vCPU -confirm:$false
- Write-host Configuring network adapter -foregroundcolor "red"
- Get-VM -name $nameselection | Get-NetworkAdapter | Set-NetworkAdapter -networkname $portgroupselection -StartConnected:$true -confirm:$false
- Write-host Configuring HDD size -foregroundcolor "red"
- Get-VM -name $nameselection | Get-HardDisk | Set-HardDisk -CapacityGB $bundleselection.Storage -confirm:$false
- Write-host Configuring VNC -foregroundcolor "red"
- Set_VMX
- Write-host Starting the VM -foregroundcolor "red"
- Start-VM -VM $nameselection
- Write-host -foregroundcolor red "Please be aware image customisation (sysprep) at the vmware level my take up to 10 minutes to finish as it involves a few reboots. The script is currently paused for 10 minutes waiting for sysprep to finish configuration so the new password can be used to expand the guest OS primary drive"
- Expand_GuestHDD
- Select_SQL
- #Open-VMConsoleWindow -vm $nameselection
- }
- #Exit
- Function Select_Exit
- {
- #Get-OSCustomizationSpec -type nonpersistent | Remove-OSCustomizationSpec -confirm:$false
- Exit
- }
- Enter_Ticket
- Select_Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement