【发布时间】:2014-03-19 21:47:26
【问题描述】:
我正在尝试从 .vhd 文件以编程方式创建 VM - 我的代码如下。我收到了一个奇怪的文件未找到错误,但我已经三重检查了我所有的路径。
ADD-VMHardDiskDrive : 'MyVM' failed to add device 'Virtual Hard Disk'. (Virtual machine ID C4A0BAFF-35EF-4B4C-9CA1-68D2ECF77BA1)
'MyVM': Attachment 'C:\temp\VMs\TheVhd.vhd' not found. Error: 'The system cannot find the file specified.' (0x80070002). (Virtual machine ID C4A0BAFF-35EF-4B4C-9CA1-68D2ECF77BA1)
我的 PowerShell 代码是:
$n = "MyVM";
$directory = "C:\temp\VMs"
$vhdxPath = "$directory\$n.vhdx";
$vhdPath = "$directory\Flash.480x800.vhd";
$vm = Get-VM $n;
if($vm -ne $null) { Remove-VM $n -Force; }
New-VM -Name $n -MemoryStartupBytes (Invoke-Expression "1000MB") -Path $directory;
Set-VMMemory -VMName $n -DynamicMemoryEnabled $true -MinimumBytes 512MB -MaximumBytes 4096MB -StartupBytes 2048MB -Buffer 20;
ADD-VMHardDiskDrive -VMName $n -Path $vhdPath;
Start-VM $n;
非常感谢任何帮助!!!谢谢!
【问题讨论】:
-
你只想要 Powershell 吗?我没有太多的powershell,我在VBS中做过。
-
PowerShell 将是理想的,因为我是如此接近。但是,是的,如果您可以向我拍摄 VBS,那会很好看。
标签: powershell virtual-machine hyper-v