Skip to content

Instantly share code, notes, and snippets.

@mikedopp
Last active March 5, 2018 16:35
Show Gist options
  • Save mikedopp/691517faee688181cd48483575a595a7 to your computer and use it in GitHub Desktop.
Save mikedopp/691517faee688181cd48483575a595a7 to your computer and use it in GitHub Desktop.
#Import Vmware PowerCli tools.
#This will work on all ISO BOOTS setups
$admin = Import-PSCredentialFromJson -Path D:\secure\admin.json
#Get-Module –ListAvailable VM* | Import-Module
Import-Module VMware.VimAutomation.Core
Import-Module VMware.VimAutomation.Cis.Core
Connect-VIServer vcenter -Credential $admin
Connect-CISServer vcenter -Credential $admin
#$createSpec.guest_OS -Split ',' | Select-String Windows
$vmlist = Import-CSV “D:\Documents\PAD_SJ_DevOps\devops_powershell\MikeD\buildtest.csv”
foreach ($item in $vmlist) {
# Map variables
$template = $item.template
$datastore = $item.datastore
$OSDiskSize = $item.OSDiskSize
$vmhost = $item.vmhost
$ISO = $item.ISO
$vmname = $item.vmname
$ip = $item.ip
$subnet = $item.subnet
$gateway = $item.gateway
$primary = $item.primary
$netadapter = $item.netadapter
$datacenter = $item.datacenter
$destfolder = $item.folder
$vlan = $item.vlan
$OSRamSize = $item.OSRamSize
$cpucount = $item.NumCPU
$domain = $item.domain
$note = $item.note
$path = $item.path #not used yet
$cred_User = $item.Cred_Username
$cred_pass = $item.Cred_Password
$SecondDiskSize = $item.SecondDiskSize
$SecondDiskDS = $item.SecondDiskDS
$GuestIDOS = $item.GuestIDOS
$spec = $item.spec
#***Mapped Variables***#
#GuestID's
# windows8Server64Guest = 2012R2
# windows9Server64Guest = 2016
$NewVMParams = @{
'VMHost' = $Vmhost
'Name' = $Vmname
'Datastore' = $DataStore
'DiskGB' = $OSDiskSize
'DiskStorageFormat' = 'Thin'
'MemoryGB' = $OSRamSize
'GuestId' = $GuestIDOS
'Version' = 'v13'
'NumCpu' = $cpucount
'Notes' = $Note
'NetworkName' = $vlan
'Location' = $destfolder
}
#'OSCustomizationSpec' = $spec
$VMname = New-VM @NewVMParams
#Mounting ISO to CD Rom
$NewCDDriveParams = @{
'VM' = $VMname
'IsoPath' = $ISO
'StartConnected' = $true
}
New-CDDrive @NewCDDriveParams
#Adding Second Disk (D DRIVE)
$NewHardDiskParams = @{
'VM' = $VMName
'CapacityGB' = $SecondDiskSize
'Datastore' = $SecondDiskDS
}
New-HardDisk @NewHardDiskParams
Start-VM -VM $VMname -RunAsync:$true #<custSpec> placement
#move-vm -vm $vmname -Destination $destfolder
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment