'powershell prompt window to take user input

I want to create a prompt box window to take a user input so that it makes the same numbers of VM as user inputs.

$clustername = Get-Cluster -Name 'BGC_CLUSTER'
$n=Read-Host -Prompt 'How many VMs you want to create'

for($i=1; $i -le $n; $i++)
{
    $name=Read-Host -Prompt 'Input your server  name'
    New-VM -Name  $name -ResourcePool $clustername -Datastore 'VV_FC10K_RAID5_BGCMW21' -DiskGB 20 -MemoryGB 2 -NumCpu 2 
    New-CDDrive -VM "$name" -IsoPath "[VV_FC10K_RAID5_BGCMW20]rhel-server-6.9-update-7-x86_64-dvd.iso" -StartConnected
    Write-Host "VM has been Created"
}

Write-Host "All VM's have been created"


Solution 1:[1]

Replace $n with below variable,You will get prompt box to enter number of VMs you want to create, $vms variable will store numbers VMs you wanted to create.

[int]$vms = [Microsoft.VisualBasic.Interaction]::InputBox("Enter number of VMs you want to create", "VMs")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DKU