filmov
tv
Automate The Creation of Virtual Machines in VMWare
Показать описание
In This Video, you will learn how to automate Virtual Machine build in VMware. In this example we are only creating single VM with Customization spec and IP address assignment but in future release we may see more parameter and more number of machines build at the same time.
You can use below script and let me know if you are facing any challenges.
=====================Script Here==================
$VMname = read-host "AUTOVM01"
$IP = "100.0.0.51"
$SNM = "255.0.0.0"
$GW = "100.0.0.1"
$DNS1 = "100.0.0.1"
$DNS2 = "100.0.0.2"
$CPU = "4"
$MemoryGB = "6"
#Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
$GC = Get-Credential -Message "Credential are required to Access Gues Windows Machine" -User Administrator
New-VM -Name $VMname -Template Win2016 -OSCustomizationSpec Windows -Datastore 'STRG-CLS01’ -DiskStorageFormat Thin -ResourcePool CLS01 -Location Mumbai
Set-VM -VM $VMname -NumCpu $CPU -MemoryGB $MemoryGB -Confirm:$false | Out-Null
Start-vm -VM $VMname
#Only show time in your script
function Get-TimeStamp {
return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}
#We are waiting here to complete Customization on VM
while($true){
Start-Sleep -Seconds 60
write-output "$(Get-TimeStamp) Waiting for Customization to be completed"
$CustomizeSuccess = Get-VIEvent -Entity $VMname | Where-Object {$_.FullFormattedMessage -Match "Customization of VM $VMname succeeded"}
$CustomizeFail= Get-VIEvent -Entity $VMname | Where-Object {$_.FullFormattedMessage -match "Customization of VM $VMname Failed"}
If ($CustomizeSuccess){
Write-host "OS Customization has completed on $VMname"
#Here we are setting IP address on the VM by using guest credential
Write-Host "Setting IP address for $VMname..."
$IPConf = Invoke-VMScript -VM $VMname -GuestCredential $GC -ScriptType bat -ScriptText $IPADD
If ($IPConf) {Write-host "IP address configured in System"} else {Write-host "IP Address assignmenet failed."
Pause
Exit}
$DNS1Conf = Invoke-VMScript -VM $VMname -GuestCredential $GC -ScriptType bat -ScriptText $DNSE1
If ($DNS1Conf) {Write-host "Primary DNS Assigned"} else {Write-host "Primary DNS assignment failed."
Pause
Exit}
$DNS2Conf = Invoke-VMScript -VM $VMname -GuestCredential $GC -ScriptType bat -ScriptText $DNSE2
If ($DNS2Conf) {Write-host "Secondary DNS configured in System"} else {Write-host "Secondary DNS assignment failed."
Pause
Exit}
Write-Host "System Build is done, Please verify the VM."
break
}
If ($CustomizeFail){
Write-host "OS Customization failed on $VMname , Press any Key to Exit the Script"
Pause
Exit
}
}
===================== Script End Here ======================
PowerCLI Exclude List of VM's From Script Deleting Snapshots in VMware
PowerCLI Power On a Suspended VMware Virtual Machine
PowerShell Installing software remotely on Multiple Computers
PowerShell Send Email if Windows Service is in Stopped State
PowerShell Send email if windows service is not running
Get Local Group Members From Remote computers
Powershell Script To Change Service Account or Update Password
Powershell How To Change Remote Computer (Workgroup) Local Account Password
Delete Virtual Machine Snapshots Older Than Specific Days
How To Create File Selection Dialog Box in PowerShell
Add User/Group To The Local Administrators/RDP Group On Multiple Computers
Get Windows Updates list from Remote Computer
PowerShell Remotely Uninstall Software from Multiple Computers
PowerShell Search Specific KB Status on Remote Computers
PowerShell Script to Connect Multiple Server's Remote Session
PowerCLI Script to power ON dedicated VMs listed in a text file
PowerCLI Script to power Off dedicated VMs listed in a text file
Delete Snapshot's from Multiple Virtual Machines
You can use below script and let me know if you are facing any challenges.
=====================Script Here==================
$VMname = read-host "AUTOVM01"
$IP = "100.0.0.51"
$SNM = "255.0.0.0"
$GW = "100.0.0.1"
$DNS1 = "100.0.0.1"
$DNS2 = "100.0.0.2"
$CPU = "4"
$MemoryGB = "6"
#Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
$GC = Get-Credential -Message "Credential are required to Access Gues Windows Machine" -User Administrator
New-VM -Name $VMname -Template Win2016 -OSCustomizationSpec Windows -Datastore 'STRG-CLS01’ -DiskStorageFormat Thin -ResourcePool CLS01 -Location Mumbai
Set-VM -VM $VMname -NumCpu $CPU -MemoryGB $MemoryGB -Confirm:$false | Out-Null
Start-vm -VM $VMname
#Only show time in your script
function Get-TimeStamp {
return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}
#We are waiting here to complete Customization on VM
while($true){
Start-Sleep -Seconds 60
write-output "$(Get-TimeStamp) Waiting for Customization to be completed"
$CustomizeSuccess = Get-VIEvent -Entity $VMname | Where-Object {$_.FullFormattedMessage -Match "Customization of VM $VMname succeeded"}
$CustomizeFail= Get-VIEvent -Entity $VMname | Where-Object {$_.FullFormattedMessage -match "Customization of VM $VMname Failed"}
If ($CustomizeSuccess){
Write-host "OS Customization has completed on $VMname"
#Here we are setting IP address on the VM by using guest credential
Write-Host "Setting IP address for $VMname..."
$IPConf = Invoke-VMScript -VM $VMname -GuestCredential $GC -ScriptType bat -ScriptText $IPADD
If ($IPConf) {Write-host "IP address configured in System"} else {Write-host "IP Address assignmenet failed."
Pause
Exit}
$DNS1Conf = Invoke-VMScript -VM $VMname -GuestCredential $GC -ScriptType bat -ScriptText $DNSE1
If ($DNS1Conf) {Write-host "Primary DNS Assigned"} else {Write-host "Primary DNS assignment failed."
Pause
Exit}
$DNS2Conf = Invoke-VMScript -VM $VMname -GuestCredential $GC -ScriptType bat -ScriptText $DNSE2
If ($DNS2Conf) {Write-host "Secondary DNS configured in System"} else {Write-host "Secondary DNS assignment failed."
Pause
Exit}
Write-Host "System Build is done, Please verify the VM."
break
}
If ($CustomizeFail){
Write-host "OS Customization failed on $VMname , Press any Key to Exit the Script"
Pause
Exit
}
}
===================== Script End Here ======================
PowerCLI Exclude List of VM's From Script Deleting Snapshots in VMware
PowerCLI Power On a Suspended VMware Virtual Machine
PowerShell Installing software remotely on Multiple Computers
PowerShell Send Email if Windows Service is in Stopped State
PowerShell Send email if windows service is not running
Get Local Group Members From Remote computers
Powershell Script To Change Service Account or Update Password
Powershell How To Change Remote Computer (Workgroup) Local Account Password
Delete Virtual Machine Snapshots Older Than Specific Days
How To Create File Selection Dialog Box in PowerShell
Add User/Group To The Local Administrators/RDP Group On Multiple Computers
Get Windows Updates list from Remote Computer
PowerShell Remotely Uninstall Software from Multiple Computers
PowerShell Search Specific KB Status on Remote Computers
PowerShell Script to Connect Multiple Server's Remote Session
PowerCLI Script to power ON dedicated VMs listed in a text file
PowerCLI Script to power Off dedicated VMs listed in a text file
Delete Snapshot's from Multiple Virtual Machines
Комментарии