This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################### | |
# Load VMware PowerCLI Module # | |
############################### | |
. 'C:\Program Files\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1' | |
cls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################### | |
# Define variables to "Connect To Server" # | |
########################################### | |
Write-Host "Enter The Following Information To Create A New VM" -ForegroundColor DarkYellow | |
Write-Host "" | |
Write-Host "" | |
Write-Host "Enter The Name Of The vCenter Or ESXi Server To Connect To: " -ForegroundColor Yellow -NoNewline | |
$ServerInstance = Read-Host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################# | |
# Define variables to "Create all VMs specified in $NewVms" # | |
############################################################# | |
Write-Host "Enter The FQDN Of The ESXi Server That Will Host The Guest VM: " -ForegroundColor Yellow -NoNewline | |
$ESXiHost = Read-Host | |
#Needed To Create An Array From The Comma Separated List Stored In "$NewVMs" | |
Write-Host "Enter The Name Of The New Guest VM " -ForegroundColor Yellow -NoNewline | |
Write-Host "(Enter Multiples As A Comma Separated List)" -ForegroundColor Green -NoNewline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################### | |
# Connect To Server # | |
##################### | |
Write-Host "" | |
Write-Host "Opening Connection To Server: " -ForegroundColor Green -NoNewline | |
Write-Host "$ServerInstance " -ForegroundColor Cyan -NoNewline | |
Write-Host "" | |
Connect-VIServer -Server $ServerInstance -Protocol https -Credential $ServerCreds | |
Write-Host "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################## | |
# Create Hash Table # | |
# Create All VMs In $NewVMs # | |
# Populate Hash Table with Id of Each VM Creation Task # | |
######################################################## | |
$TaskTable = @{} | |
foreach ($VM in $NewVMs){ | |
$TaskTable[(New-VM -Name $VM -Template $VMTemplate -VMHost $ESXiHost -Location $VMLocation -Datastore $VMDatastore -RunAsync).Id] = $VM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################### | |
# Display VM Build Status # | |
########################### | |
$RunningTasks = $TaskTable.Count | |
while($RunningTasks -gt 0){ | |
Get-Task | foreach { | |
if($TaskTable.ContainsKey($_.Id) -and $_.State -eq "Success"){ | |
Write-Host " VM " -ForegroundColor Green -NoNewline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################## | |
# Disconnect From Server # | |
########################## | |
Write-Host "" | |
Write-Host "Closing Connection To Server: " -ForegroundColor Green -NoNewline | |
Write-Host "$ServerInstance " -ForegroundColor Cyan | |
Disconnect-VIServer -Server $ServerInstance -Force -Confirm:$false | |
Write-Host "" | |
Write-Host "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################### | |
# Load VMware PowerCLI Module # | |
############################### | |
. 'C:\Program Files\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1' | |
cls | |
########################################### | |
# Define variables to "Connect To Server" # | |
########################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Deploy-VM { | |
[CmdletBinding()] | |
Param ( | |
[parameter (Mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
$VMNames | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Deploy-VM { | |
Param ( | |
[parameter (Mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
$VMNames | |
) | |
} |
OlderNewer