Powershell 获取本地计算机上虚拟机的虚拟机间歇性故障
我们最近开始在一些操纵VM的powershell脚本上出现间歇性故障。我能够将问题归结为以下几点:Powershell 获取本地计算机上虚拟机的虚拟机间歇性故障,powershell,hyper-v,Powershell,Hyper V,我们最近开始在一些操纵VM的powershell脚本上出现间歇性故障。我能够将问题归结为以下几点: $ErrorActionPreference = "Stop" for ($i=0;$i -lt 100000; $i=$i+1) {get-vm * | write-host} 此命令将运行并打印本地Hyper-V虚拟机(目前有4个)一段时间(数百或数千次),但最终将失败: PS>TerminatingError(Get-VM): "The running command stopped
$ErrorActionPreference = "Stop"
for ($i=0;$i -lt 100000; $i=$i+1) {get-vm * | write-host}
此命令将运行并打印本地Hyper-V虚拟机(目前有4个)一段时间(数百或数千次),但最终将失败:
PS>TerminatingError(Get-VM): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The computer 'LOCALNAME' could not be resolved. Make sure you typed the machine name correctly and that you have network access."
然后,我可以查看当前的$Error变量,以获得有关异常堆栈的更多信息,我已经在下面粘贴了异常堆栈。本地计算机的名称是LOCALNAME
。关于什么可能导致这种间歇性故障或如何诊断它,有什么想法吗?到目前为止,我已经在没有任何运气的情况下查看了事件日志,我很快就可以重新想象这台机器了
PSMessageDetails :
Exception : Microsoft.HyperV.PowerShell.VirtualizationException: The computer 'LOCALNAME' could not
be resolved. Make sure you typed the machine name correctly and that you have network access.
---> Microsoft.Virtualization.Client.Management.ServerConnectionException: The computer
'LOCALNAME' could not be resolved. Make sure you typed the machine name correctly and
that you have network access.
at Microsoft.Virtualization.Client.Management.ServerNames.Resolve(String nameToResolve,
IUserPassCredential credential)
at Microsoft.Virtualization.Client.Management.Server.GetServer(String name,
IUserPassCredential credential)
at Microsoft.HyperV.PowerShell.Commands.ParameterResolvers.GetServers(IServerParameters
cmdletParameters, IOperationWatcher operationWatcher)
at Microsoft.HyperV.PowerShell.Commands.ParameterResolvers.ResolveVirtualMachines(IVirtualMa
chineCmdlet vmCmdlet, IOperationWatcher operationWatcher, ErrorDisplayMode errorDisplayMode)
at Microsoft.HyperV.PowerShell.Commands.GetVM.EnumerateOperands(IOperationWatcher
operationWatcher)
at
Microsoft.HyperV.PowerShell.Commands.VirtualizationCmdlet`1.PerformOperation(IOperationWatcher
operationWatcher)
at Microsoft.HyperV.PowerShell.Commands.VirtualizationCmdletBase.PerformOperationWithLogging
(IOperationWatcher operationWatcher)
我们也遇到过类似的问题——将范围缩小到DNS随机丢弃。我写了一个nslookup检查,循环了数十万次,并记录了它的成功/失败。我们能够准确地指出,每小时一到两次,DNS将停止解析任何内容仅一两秒钟,然后恢复。仍然不确定DNS错误的根本原因,但这是导致我们的应用程序错误的原因。只是一个想法!谢谢你的想法,尼克。我认为这实际上也是我们正在发生的事情。我们的dns服务器在出现至少一些问题的时候出现了故障。有点奇怪,这是本地机器的感觉。。。如果它再次发生,我可能会看到将-ComputerName指定为127.0.0.1是否有助于避免尝试查找名称