Booting from an ISO Image Using PowerCLI Scripts

How to make the following script work? Currently, I can create a new virtual machine on my server. I also want to download a Windows ISO image and perform an unattended installation on a virtual machine. How to edit a script to make this work?

# 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
}
+3
source share
1 answer

My problem is with the ISO PATH image. I get an error "Invalid data store format"

You specify isopath using a parameter IsoPath, which is the data store path to the ISO, and not just the ISO name. You do not specify any data storage from your code.

:

"[yourdatastore] IsoFolder\$iso"

PowerCLI :

$cd = New-CDDrive -VM $vm -ISOPath "[sof-20666-esx:storage1] ISO\testISO.iso"
Set-CDDrive -CD $cd -StartConnected -Connected
+3

All Articles