Thursday, April 9, 2015

The ultimate VM batch deployment script - VMWare

The ultimate VM batch deployment script - VMWare 

link




*.ps1

# Load Windows PowerShell cmdlets for managing vSphere
Add-PsSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"

#
# PowerCLI to create VMs from existing vSphere VM
# Version 1.0
# Magnus Andersson RTS
#
# Specify vCenter Server, vCenter Server username and vCenter Server user password
#Get vCenter Details : vCenter name, User, password
Write-Host "Please enter the vCenter Host Name :"
Write-Host " "
$vCenterName = vcenter.local
$Username = domain\user
$SecurePassword = Read-Host Password -AsSecureString

#Convert Secure Password to Plain Text
$PASS = `
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($PASS)
#Connect to vCenter
Connect-VIServer -Server $vCenterName -User $Username -Password $PlainPassword

#
# Specify number of VMs you want to create
$vm_count = “10“
#
# Specify the VM you want to clone
$clone = “test“
#
# Specify the Customization Specification to use
$customspecification=”test-customization“
#
# Specify the datastore or datastore cluster placement
$ds = “DataStore1“
#
# Specify vCenter Server Virtual Machine & Templates folder
$Folder = “test folder“
#
# Specify the vSphere Cluster
$Cluster = “Cluster-LAB“
#
# Specify the VM name to the left of the – sign
$VM_prefix = “Test-0“
#
# End of user input parameters
#_______________________________________________________
#
write-host “Connecting to vCenter Server $vCenter” -foreground green
Connect-viserver $vCenter -user $vCenterUser -password $vCenterUserPassword -WarningAction 0
1..$vm_count | foreach {
$y=”{0:D2}” -f $_
$VM_name= $VM_prefix + $y
$ESXi=Get-Cluster $Cluster | Get-VMHost -state connected | Get-Random
write-host “Creation of VM $VM_name initiated” -foreground green
New-VM -Name $VM_Name -VM $clone -VMHost $ESXi -Datastore $ds -Location $Folder -OSCustomizationSpec $customspecification -RunAsync
}
#Remove-VM -VM $delete -DeleteFromDisk -Confirm:$false -RunAsync | Out-Null}


No comments:

Post a Comment

Vmware NSX SSL creation 

Using OpenSSL for NSX Manager SSL import: Creates CSR and 4096 bit KEY Creating NSX 6.4.2 SSL    openssl req -out nsxcert.csr -newkey rsa:40...