gpt4 book ai didi

Powershell Hyper-V 脚本不起作用? + 自动安装 Windows

转载 作者:行者123 更新时间:2023-12-03 01:20:38 26 4
gpt4 key购买 nike

所以我有一个奇怪的问题。当我执行这样的命令时:

New-VM -Name "MattTest" -MemoryStartupBytes 2GB -BootDevice CD -SwitchName Lab -path c:\VMdocs -NewVHDSizeBytes 40GB –NewVHDPath c:\base.vhdx

Set-VMDvdDrive -VMName MattTest -Path C:\ISOFiles\Windows2008.

Start-VM -Name MattTest

它工作正常,但是如果我制作一个脚本,我会收到大量错误,例如在名为 PS.ps1 并通过 Powershell 运行的脚本中完全相同的东西,我得到:

New-VM : The parameter is not valid. No switch can be found by given criteria. At C:\Users\mrsmith\Desktop\PS.ps1:1 char:1 + New-VM -Name "MattTest" -MemoryStartupBytes 2GB -BootDevice CD -SwitchName Lab - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (Lab:String) [New-VM], VirtualizationInvalidArgumentException + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.NewVMCommand

Set-VMDvdDrive : The parameter is not valid. Hyper-V was unable to find a virtual machine with name MattTest. At C:\Users\mrsmith\Desktop\PS.ps1:3 char:1 + Set-VMDvdDrive -VMName MattTest -Path C:\ISOFiles\Windows2008. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (MattTest:String) [Set-VMDvdDrive], VirtualizationInvalidArgumentExcept ion + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.SetVMDvdDriveCommand

Set-VMDvdDrive : The parameter is not valid. No DVD drives are found. At C:\Users\mrsmith\Desktop\PS.ps1:3 char:1 + Set-VMDvdDrive -VMName MattTest -Path C:\ISOFiles\Windows2008. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Set-VMDvdDrive], VirtualizationInvalidArgumentException + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.SetVMDvdDriveCommand

Start-VM : The parameter is not valid. Hyper-V was unable to find a virtual machine with name MattTest. At C:\Users\mrsmith\Desktop\PS.ps1:5 char:1 + Start-VM -Name MattTest + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (MattTest:String) [Start-VM], VirtualizationInvalidArgumentException + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.StartVMCommand



我不确定是什么原因造成的?是否与模块有关,因为我已经检查过并且 Hyper-V cmdlet 正在运行(考虑到我可以手动输入这些,它们会很好)

还有一个附带问题:这些说明将进入“安装 Windows XXXX”屏幕。有没有办法自动化这个过程?或者不是真的(比如让它点击下一步,选择一个硬盘驱动器,安装等等......

最佳答案

只是为了确保提示符(例如“PS C:\Users\mrsmith\Desktop>”)不是脚本的一部分,对吧?如果是这样删除它。

看起来,它是脚本的一部分,因为 PSGet-Process 的别名它尝试将“C:\Users\mrsmith\Desktop”作为进程名称传递。

关于Powershell Hyper-V 脚本不起作用? + 自动安装 Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15272049/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com