Last active
November 20, 2025 21:42
-
-
Save kobutton/364d21445ba0f42afdd57ed261526df2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Connect-ViServer vcsa.home.kobutton.com | |
| param ( | |
| [Parameter(Mandatory=$true)] | |
| [string]$MACFile, # File Container Macaddresses to add, one per line, all uppercase, with colons | |
| [Parameter(Mandatory=$true)] | |
| [String]$EsxiCluster, #Target Esxi Cluster | |
| [Parameter(Mandatory=$true)] | |
| [String]$VMPrefix, # Prefix for macdummy_vms | |
| [Parameter(Mandatory=$true)] | |
| [String]$TargetNetwork #TargetVMWare Network Name for Network Adapters | |
| ) | |
| function Create-Dummy-VM{ | |
| param ( | |
| [string]$name, | |
| [VMware.VimAutomation.ViCore.Impl.V1.Inventory.ComputeResourceImpl]$Cluster | |
| ) | |
| #Create a new VM | |
| $vm = New-Vm -Name $name -ResourcePool $Cluster -DiskMB 1 -MemoryMB 4 | |
| #delete the initial harddisk | |
| $vm | Get-HardDisk | Remove-HardDisk -Confirm:$false | |
| #delete the initial network | |
| $vm | Get-NetworkAdapter | Remove-NetworkAdapter -Confirm:$false | |
| return $vm | |
| } | |
| $macs = Get-Content -Path $MACFile | |
| $cluster = Get-Cluster -name $EsxiCluster | |
| $nic_counter = 10 #start the nic_counter at 10 to create a new VM | |
| $indexer = 0 | |
| $macs | ForEach-Object { | |
| if ($nic_counter % 10 -eq 0 ){ | |
| $new_vm_name = $VMPrefix + $indexer | |
| $vm = Create-Dummy-VM -Name $new_vm_name -Cluster $cluster | |
| if (($nic_counter -eq 10) -and ($indexer -eq 0)){ | |
| $nic_counter = 0 | |
| } | |
| $indexer++ | |
| } | |
| $vm | New-NetworkAdapter -NetworkName $TargetNetwork -MacAddress $_ #this seems to error all the time but it always completes | |
| $nic_counter ++ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment