Power shell script to create and clone 100 VMs from one storage and move send 10000 Iops on each VM

# Connect to the vCenter Server
Connect-VIServer -Server <vCenterServer> -User <username> -Password <password>

# Specify the source VM and storage
$sourceVM = "SourceVM"
$sourceDatastore = "SourceDatastore"

# Specify the destination datastore
$destinationDatastore = "DestinationDatastore"

# Specify the number of VMs to create and clone
$numberOfVMs = 100

# Specify the number of IOPS to send on each VM
$iops = 10000

# Loop through and create/cloning VMs
for ($i = 1; $i -le $numberOfVMs; $i++) {
    $newVMName = "VM$i"

    # Clone the VM from the source to the destination datastore
    $cloneSpec = New-Object VMware.Vim.VirtualMachineCloneSpec
    $cloneSpec.Location = New-Object VMware.Vim.VirtualMachineRelocateSpec
    $cloneSpec.Location.Datastore = Get-Datastore -Name $destinationDatastore
    $cloneSpec.PowerOn = $false

    $sourceVMObj = Get-VM -Name $sourceVM
    New-VM -Name $newVMName -VM $sourceVMObj -Location (Get-Folder) -Datastore (Get-Datastore -Name $destinationDatastore) -CloneSpec $cloneSpec

    # Power on the newly created VM
    Start-VM -VM $newVMName

    # Send IOPS on the VM
    $vm = Get-VM -Name $newVMName
    $disk = $vm | Get-HardDisk
    $disk | Set-HardDisk -Iops $iops
}

# Disconnect from the vCenter Server
Disconnect-VIServer -Server <vCenterServer> -Confirm:$false

Make sure to replace “, “, “, “, “, “ with your actual vCenter Server details and VM/storage names. Please note that this script assumes you have the VMware PowerCLI module installed and properly configured.

Leave a comment