如何使以下脚本工作?目前我可以在我的服务器中创建一个新的虚拟机。我还希望加载 Windows ISO 镜像并在虚拟机中进行无人值守安装。我应该如何编辑脚本才能使其正常工作?
# Virtual Center Details
$server_address = "xxxxx"
$username = "xxxxx"
$password = "xxxxx"
$iso = "WINXP_X86_SP3_CD.ISO"
Get-VIServer -Server $server_address -Protocol https -User $username -Password $password
foreach ($vmm in $array)
{
$vmm = "VirtualMachine"
New-VM -name $vmm -DiskMB 20000 -memoryMB 2000
Get-VM $vmm | Get-CDDrive | Set-CDDrive -IsoPath $iso -StartConnected $true -Confirm:$false
$value = "5000"
$vm = Get-VM $vmname | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $value
$vm.ReconfigVM_Task($vmConfigSpec)
Start-vm -vm $vmname
}
最佳答案
my issue is with the ISO PATH image. I am getting the error "Invalid datastore format"
您正在使用 IsoPath
参数指定 isopath,该参数是 ISO 的数据存储路径,而不仅仅是 ISO 名称。从您的代码中您没有指示任何数据存储。
数据存储路径的语法是:
"[yourdatastore] IsoFolder\$iso"
从在线 PowerCLI 引用中获取的示例:
$cd = New-CDDrive -VM $vm -ISOPath "[sof-20666-esx:storage1] ISO\testISO.iso"
Set-CDDrive -CD $cd -StartConnected -Connected
关于powershell - 使用 PowerCLI 脚本从 ISO 镜像启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6212767/