diff --git a/powershell/hyperv/hyperv.go b/powershell/hyperv/hyperv.go index 67ad79d82..410678ee4 100644 --- a/powershell/hyperv/hyperv.go +++ b/powershell/hyperv/hyperv.go @@ -171,6 +171,17 @@ Remove-VMDvdDrive -VMName $vmName -ControllerNumber $controllerNumber -Controlle return err } +func DeleteAllDvdDrives(vmName string) error { + var script = ` +param([string]$vmName) +Get-VMDvdDrive -VMName $vmName | Remove-VMDvdDrive +` + + var ps powershell.PowerShellCmd + err := ps.Run(script, vmName) + return err +} + func MountFloppyDrive(vmName string, path string) error { var script = ` param([string]$vmName, [string]$path) @@ -220,7 +231,7 @@ New-VM -Name $vmName -Path $path -MemoryStartupBytes $memoryStartupBytes -NewVHD return err } - return DeleteDvdDrive(vmName, 1, 0) + return DeleteAllDvdDrives(vmName) } }