filmov
tv
PowerCLI Automate multiple Virtual Machines Creation in vCenter using CSV file
Показать описание
In This Video, you will learn how to automate multiple Virtual Machine build. We are using CSV file to give input for PowerShell script and whatever information you have used in *csv file, it will be used to build the VM's.
You can use below script and let me know if you are facing any challenges.
======Script Here=====
$vms = Import-CSV "E:\VMList.CSV"
foreach ($vm in $vms)
{
#Assigning variables as per CSV File
$VMName =$vm.Name
$Template = Get-Template -name $vm.Template
$Cluster = $vm.Cluster
$Datastore = Get-Datastore -Name $vm.Datastore
$Custom = Get-OSCustomizationSpec -Name $vm.Customization
$vCPU = $vm.vCPU
$Memory = $vm.Memory
$Network = $vm.Network
$Location = $vm.Location
$IPaddress = $vm.IPaddress
$Subnetmask = $vm.Subnetmask
$DefaultGateway = $vm.DefaultGateway
$PrimaryDNS = $vm.PrimaryDNS
$SecondaryDNS = $vm.SecondaryDNS
#Assign Network Details to Custom Template
Get-OSCustomizationSpec $Custom | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IPaddress $IPaddress -Subnetmask $Subnetmask -DefaultGateway $DefaultGateway -Dns $PrimaryDNS,$SecondaryDNS
#Deploying the VM
New-VM -Name $VMName -Template $Template -ResourcePool (Get-Cluster $Cluster | Get-ResourcePool) -location $location -StorageFormat Thin -Datastore $Datastore -OSCustomizationSpec $Custom
Start-Sleep -Seconds 10
#Set vCPU, Memory and Network (VLAN) and Additonal HDD to VM
$NewVM = Get-VM -NAME $VMName
$NewVM | Set-VM -MemoryGB $Memory -NumCpu $vCPU -Confirm:$false
$NewVM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $Network -Confirm:$false
#Add additonal HDD if present
#Start the VM to continue the customization process
Start-VM -VM $NewVM -Confirm:$false
#Remove Network Details to Custom Template
#Get-OSCustomizationSpec $Custom | Get-OSCustomizationNicMapping | Remove-OSCustomizationNicMapping -Confirm:$false
}
======= Script End ==========
PowerShell Remotely Uninstall Google Chrome on Multiple Remote Computers
PowerShell Uninstall WinRAR Software Silently on Multiple Remote Computers
Find the Current User Logged on Remote Computer and Take Action
Remove User Account or Group from Local Groups on Remote Computers
Automate The Creation of Virtual Machines in VMWare
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
Create Snapshot on Multiple Virtual Machine
How can I check if a port is open remotely
Installing software remotely on Multiple "Workgroup" Computers
PowerShell Installing software remotely on Multiple Computers
Unable to move OU in Active Directory (Access is denied)
PowerShell Installing software remotely on Multiple Computers
Get Multiple Services Status Remotely | Remotely Start or Stop Services
Get Date and Time from Multiple Remote Computers
PowerCLI - How to get HA restarted VM's List
Get-Childitem - Search file on Local and Remote Computers
You can use below script and let me know if you are facing any challenges.
======Script Here=====
$vms = Import-CSV "E:\VMList.CSV"
foreach ($vm in $vms)
{
#Assigning variables as per CSV File
$VMName =$vm.Name
$Template = Get-Template -name $vm.Template
$Cluster = $vm.Cluster
$Datastore = Get-Datastore -Name $vm.Datastore
$Custom = Get-OSCustomizationSpec -Name $vm.Customization
$vCPU = $vm.vCPU
$Memory = $vm.Memory
$Network = $vm.Network
$Location = $vm.Location
$IPaddress = $vm.IPaddress
$Subnetmask = $vm.Subnetmask
$DefaultGateway = $vm.DefaultGateway
$PrimaryDNS = $vm.PrimaryDNS
$SecondaryDNS = $vm.SecondaryDNS
#Assign Network Details to Custom Template
Get-OSCustomizationSpec $Custom | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IPaddress $IPaddress -Subnetmask $Subnetmask -DefaultGateway $DefaultGateway -Dns $PrimaryDNS,$SecondaryDNS
#Deploying the VM
New-VM -Name $VMName -Template $Template -ResourcePool (Get-Cluster $Cluster | Get-ResourcePool) -location $location -StorageFormat Thin -Datastore $Datastore -OSCustomizationSpec $Custom
Start-Sleep -Seconds 10
#Set vCPU, Memory and Network (VLAN) and Additonal HDD to VM
$NewVM = Get-VM -NAME $VMName
$NewVM | Set-VM -MemoryGB $Memory -NumCpu $vCPU -Confirm:$false
$NewVM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $Network -Confirm:$false
#Add additonal HDD if present
#Start the VM to continue the customization process
Start-VM -VM $NewVM -Confirm:$false
#Remove Network Details to Custom Template
#Get-OSCustomizationSpec $Custom | Get-OSCustomizationNicMapping | Remove-OSCustomizationNicMapping -Confirm:$false
}
======= Script End ==========
PowerShell Remotely Uninstall Google Chrome on Multiple Remote Computers
PowerShell Uninstall WinRAR Software Silently on Multiple Remote Computers
Find the Current User Logged on Remote Computer and Take Action
Remove User Account or Group from Local Groups on Remote Computers
Automate The Creation of Virtual Machines in VMWare
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
Create Snapshot on Multiple Virtual Machine
How can I check if a port is open remotely
Installing software remotely on Multiple "Workgroup" Computers
PowerShell Installing software remotely on Multiple Computers
Unable to move OU in Active Directory (Access is denied)
PowerShell Installing software remotely on Multiple Computers
Get Multiple Services Status Remotely | Remotely Start or Stop Services
Get Date and Time from Multiple Remote Computers
PowerCLI - How to get HA restarted VM's List
Get-Childitem - Search file on Local and Remote Computers
Комментарии