Hi There ,
I need to created multiple virtual machines at the same time . kindly share if any one having the exact and executable script . it will help full to reduce the time taking in production environment
I have a great script that leverages PowerCLI, OSCustomization, Templates and CSV files. It was written with myself and LucD. I can send them to you tomorrow if you wish. Thanks, BostonTechGuy
Any chance of posting that script here?
Hi Please share the script .
Sure. Got dragged into a number of projects. Sorry for not posting. I am not a professional coder/script writer. I have lived in the Windows world of Administration far too long. So alot of the code is direct and without comments. I will give a quick break down of how to use it here.
Description:
This script was developed a number of years ago with huge assistance from LucD. You may have seen it in other postings. Its also geared towards Windows Servers. I have not used in on Linux servers. If you know what changes are needed to make it Linux friendly please feel free to update it and share with others.
The whole script works with CSV File, Powershell Loops, and OS CustomizationSpec.
FIRST: create a customization spec in vCenter to get the general options that will always be the same on every box completed. Settings like Domain Access and such. Dont worry about IPs and names. We are going to modify those in real time with the script.
SECOND: Get the script changed to your specs. vCenter name and the like. In order for this to work, you need the first row in the CSV to be Headers of the variables in the script. MOST IMPORTANT: Punctuation is not forgivable. What is in the CSV must match EXACTLY whats in the script. I have made this error more than once :smileylaugh:
SCRIPT: (NOTE: I made several attempts to get the HTML code correct for this to appear correctly and failed. I have placed the whole thing in a quote instead..)
<# Deploy VMs with Custom Specs for Automated Deployments with Static IP Addresses and Domain Access Hosts within a Cluster. Written by Boston Tech Guy May 2,2013 Last Updated June 13, 2015 #>
# List to deploy from. Standard CSV file with headings for script to pull from
$deploylist = "<Location of CSV File>\name of CSV.csv"
# VCenter you are connecting too. For the name, use FQDN
$vcserver = "<Name of VCENTER to connect to>"
# Connect to vCenter server. It will use cache creds of user logged into workstation
Connect-VIServer $vcserver
# Deployment loop and customization done during server creation
Import-Csv $deploylist -UseCulture | %{
Get-OSCustomizationSpec $_."Customization" | Get-OSCustomizationNicMapping | `
Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_."IP Address" `
-SubnetMask 255.255.255.0 -DefaultGateway $_."Gateway" -Dns $_."First DNS",$_."Second DNS"
New-VM -Name $_."Server Name" -Template $_."Template" -VMHost $_."Esx Host" `
-Datastore $_."Datastore" -OSCustomizationSpec $_."Customization" `
-Confirm:$false -RunAsync
}
Disconnect-VIServer -Confirm:$false
<#
NOTES:
This script was written in a template format. It can easily be modified.
Since majority of the Subnet Masks at most companies are the same, the number is hard coded. However it can easily be changed
If deploying a number of servers on same domain, the DNS entries can also be hard coded.
This script also is not forgiving on punctuation. Host, VM Template, VM Customization Script and Server Names MUST BE EXACT!
Given the number of servers that could be deployed and resources needed to generate those
servers, this script does not assign Port Groups or Powers on the server. Servers do not complete
in a timable fashion. Its somewhat random when a server completes. Therefor a second script
has been created to perform those task. That script should be ran once the last server has
been deployed from this script.
#>
As you can see couple things are going here. During the first loop the Customization Spec is changed for the next VM you are going to deploy. The second part of the script actually builds the New VM. Then the loop starts over again with the next row in the CSV. Wash, Rinse, Repeat.
Key couple points
Here is what the first couple of rows would look like on the CSV
Server Name ESX Host Datastore Template Customization IP Address Gateway First DNS Second DNS VLAN Name of VM Host Name Datastore Name Template Name OS Customize Spec Name 192.168.1.100 192.168.1.1 192.168.1.101 192.168.1.102 Servers
I have used this script to deploy hundreds of VMs at a single time. Again to repeat, the speed of the deployments depends on what the Hosts are doing. If a lot of vMotions are going on, the Hosts will queue the builds.
Questions?
Thanks,
Boston Tech Guy