开发者

Booting from an ISO image using PowerCLI scripts

How do I make the following script work? Currently I am able to create a new virtual machine in my server. I wish to also load the Windows ISO image and do an unattended installation in the virtual machine. How shall I edit the script to make this work?

# Virtual Center Details
$server_address = "xxxxx"
$username = "xxxxx"
$password = "xxxxx"
$iso = "开发者_JAVA技巧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"

You are specifying isopath using IsoPath parameter, which is the datastore path to the ISO, not simply the ISO name. From your code you are not indicating any datastore.

The syntax for a datastore path is:

"[yourdatastore] IsoFolder\$iso"

Example got from PowerCLI reference online:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜