search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | No Comment | 1,904 views | 21/06/2013 16:55

You can search a VM name in your Hyper-V host list like this:

$VMName = "Server Name"
$Servers = Get-Content C:\servers.txt
foreach ($Server in $Servers)
{
	$VMs = Get-WMIObject -Class Msvm_ComputerSystem -Namespace "root\virtualization" -ComputerName $Server
	foreach ($VM in $VMs)
	{
		if ($VM.ElementName -eq $VMName)
		{
			Write-Host $Server
		}
	}
}

It uses WMI so both works on Windows Server 2008 and Windows Server 2012.