powershell - 使用 PowerCLI 脚本从 ISO 镜像启动

标签 powershell virtualization vmware virtual-machine powercli

如何使以下脚本工作?目前我可以在我的服务器中创建一个新的虚拟机。我还希望加载 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/

相关文章:

macos - 使用Application Uploader时的Mac OS X vmware guest虚拟机 'failed to open ssh session. (16)'

python - 检索每个虚拟机的 VirtualDisk 的存储策略

powershell - 如何在PowerShell中使变量成为范围?

powershell - 依靠PowerShell中的空列表

unix - Docker 不会以用户身份运行命令

wpf - TreeView 因覆盖控件模板而失去虚拟化

cloud - 为什么centos6.0去掉了对xen的支持

powershell - 将选定项目从一个文件夹复制到新文件夹

powershell - 将参数从 ps1 发送到其他 ps1

python - 如何在linux上的python中安装模块autopy?