我想创建一个提示框窗口以接受用户输入,以便它制作与用户输入相同数量的VM。
$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"
答案 0 :(得分:0)
用下面的变量替换$ n,您将得到提示框,输入要创建的虚拟机数量,$ vms变量将存储要创建的虚拟机数量。
[int]$vms = [Microsoft.VisualBasic.Interaction]::InputBox("Enter number of VMs you want to create", "VMs")