Skip to content

Instantly share code, notes, and snippets.

Get-VM | Get-CDDrive | where {$_.IsoPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$False
############################################
# Get User Credentials To Pass To Guest OS #
############################################
$Creds = Get-Credential
######################################################################
# Get All CentOS Linux VMs With A Configured ISO Path #
# Use Invoke-VMScript To Eject The Mounted Media Inside The Guest OS #
# Disconnect The ISO From The VM #
Function Deploy-VM {
[CmdletBinding()]
Param (
[parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$VMNames
)
Function Deploy-VM {
[CmdletBinding()]
Param (
[parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$VMNames
)
Function Deploy-VM {
Param (
[parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$VMNames
)
}
Function Deploy-VM {
[CmdletBinding()]
Param (
[parameter (Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$VMNames
)
###############################
# Load VMware PowerCLI Module #
###############################
. 'C:\Program Files\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'
cls
###########################################
# Define variables to "Connect To Server" #
###########################################
##########################
# 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 ""
###########################
# 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
########################################################
# 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