Skip to content

Instantly share code, notes, and snippets.

@2vcps
Created July 27, 2018 15:01
Show Gist options
  • Save 2vcps/c484c24238dc2c2df64449aa8a71c303 to your computer and use it in GitHub Desktop.
Save 2vcps/c484c24238dc2c2df64449aa8a71c303 to your computer and use it in GitHub Desktop.
IP IP2
192.168.1.121 192.168.230.121
192.168.1.122 192.168.230.122
192.168.1.123 192.168.230.123
192.168.1.124 192.168.230.124
192.168.1.125 192.168.230.125
192.168.1.126 192.168.230.126
192.168.1.127 192.168.230.127
192.168.1.128 192.168.230.128
# We will name the VMs "VM-001", "VM-002" … "VM-100"
write-host "You ain't the boss of me."
$numVM = read-host "Enter the Number of VM's you wish me to deploy"
$prefixVM = read-host "Enter the lab prefix"
$vmNameTemplate = $prefixVM + "-{0:D3}"
#set the default csv name but allow user to specify their own if needed.
$csvName = "jo_kubernetes.csv"
#$csvName = read-host "What IP list should I use? (jo_kuberenetes.csv)"
# The VMs will be created in "MyCluster" and will be based on "Rhel6_VM" template
$cluster = Get-Cluster vsan
$template = Get-Template xenialimg
# Create the VMs
$vmList = @()
for ($i = 1; $i -le $numVM; $i++) {
$vmName = $vmNameTemplate -f $i
write-host $vmName
$vmList += New-VM -Name $vmName -ResourcePool $cluster -Template $template
}
# The list of static IPs is stored in "StaticIPs.csv" file
$staticIpList = Import-CSV $csvName
# Create the customization specification . This time we will directly create a non-persistent specification, so we don’t need to specify a name for it
$linuxSpec = New-OSCustomizationSpec -Domain 2vcps.local -DnsServer "192.168.1.10", "192.168.1.11" -NamingScheme VM -OSType Linux -Type NonPersistent
# Now apply the customization specification to each VM
for ($i = 0; $i -lt $vmList.Count; $i++) {
# Acquire a new static IP from the list
$ip = $staticIpList[$i].IP
#$ip2 = $staticIpList[$i].IP2
# Remove any NIC mappings from the specification
$nicMapping = Get-OSCustomizationNicMapping -OSCustomizationSpec $linuxSpec
Remove-OSCustomizationNicMapping -OSCustomizationNicMapping $nicMapping -Confirm:$false
# Retrieve the VM’s network adapter on the "Public" network
$publicNIC = $vmList[$i] | Get-NetworkAdapter | Where-Object {$_.NetworkName -eq "VM Network"}
# Retrieve the VM’s network adapter on the "Private" network
#$privateNIC = $vmList[$i] | Get-NetworkAdapter | where {$_.NetworkName -eq "iSCSI-A"}
# Create a NIC mapping for the "Public" NIC - it will use static IP
$linuxSpec | New-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ip -SubnetMask "255.255.255.0" -DefaultGateway "192.168.1.1" -NetworkAdapterMac $publicNIC.MacAddress
# Create a NIC mapping for the "Private" NIC - it will use DHCP and we will map it by MAC address
#$linuxSpec | New-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ip2 -SubnetMask "255.255.255.0" -DefaultGateway "192.168.230.1" -NetworkAdapterMac $privateNIC.MacAddress
# Apply the customization
Set-VM -VM $vmList[$i] -OSCustomizationSpec $linuxSpec -Confirm:$false
Set-VM -VM $vmList[$i] -MemoryGB 16 -NumCpu 2 -Confirm:$false
Start-VM -VM $vmList[$i]
Write-Host $vmList[$i] "is Now powered ON"
}
write-host "Burninator."
$numVM = read-host "Enter the Number of VM's you wish me to destroy"
$prefixVM = read-host "Enter the lab prefix"
$vmNameTemplate = $prefixVM + "-{0:D3}"
$cluster = Get-Cluster Lab
$template = Get-Template ubtk8stemplate
# Create the VMs
$vmList = @()
for ($i = 1; $i -le $numVM; $i++) {
$vmName = $vmNameTemplate -f $i
$vmList += stop-vm -VM $vmName -Confirm:$false -RunAsync
$vmList += remove-vm -VM $vmName -DeletePermanently -Confirm:$false -RunAsync
write-host $vmName + "Burninated"
}
@2vcps
Copy link
Author

2vcps commented Jul 27, 2018

Make sure to modify the Variable to fit your environment.
Now everyone knows my homelab use 192.168.1.0 subnet!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment