PowerShell:如何返回 Hyper-V 群集中的所有 VM

标签 powershell windows-server-2012 hyper-v failovercluster

我是第一次使用 PowerShell 的程序员。在 Windows Server 2012 上运行。

我正在尝试获取故障转移群集上所有 VM 的列表,并且正在处理此问题:

$clusterNodes = Get-ClusterNode | select Name 
ForEach($item in $clusterNodes)
{Get-VM -ComputerName $item}

这会返回一堆错误

然而,这工作得很好
$hosts = "server1", "server2", "server3", "server4"
ForEach($item in $hosts)
{Get-VM -ComputerName $item}

是不是因为Get-ClusterNode 失败了?选择名称返回以下内容?
Name
----
server1
server2
server3
server4

有标题和下划线?

最佳答案

试一试:

$clusterNodes = Get-ClusterNode;
ForEach($item in $clusterNodes)
{Get-VM -ComputerName $item.Name; }

您必须引用 Name Get-ClusterNode 返回的对象的属性.

关于PowerShell:如何返回 Hyper-V 群集中的所有 VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21409249/

相关文章:

powershell - 如何使用 powershell 在 HyperV VM 上启用 EnhancedSessionTransportType?

powershell - 远程Powershell返回值

windows - Windows 2012 如何选择 Internet 与 DataCenter 的网络过滤器设置,如 netstat -y 中所示

iis - 使用 OpenSSL 的 IIS 上不受信任的证书

产品配置期间 SharePoint 2013 SP1 安装错误 : Step 5 Failed, 超时

android - 在 Windows (10 Home) 中找不到 Hyper-V 选项打开/关闭启用 VT-x 以安装仿真器加速器 (HAXM) 的功能

powershell - 我的代码不会写 "No files to process"

Azure 的 New-AzureRmHDInsightCluster 命令不接受记录的 ComponentVersion 选项

powershell - 如何在 Team Build 2013 Post-Test 脚本中检测测试运行是否成功?

python - 将 Django 应用程序从本地主机应用程序部署到 Web 应用程序