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

Badges
MCSE
Community

Cozumpark Bilisim Portali
List all Virtual Machines and export it to text file with Powershell
Posted in Virtual Machine Manager, Windows Powershell | 1 Comment | 5,740 views | 20/06/2009 08:32

Lets list all Virtual Machines in our environment with Powershell.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
Get-Vmmserver localhost
$VMProp = Get-VM | Select-Object -Property Name,OperatingSystem
clear-content -path "C:\VMList.txt"
$vxcount=0;
$vmcount=0;
foreach ($i in $VMProp)
{
	$VMName = $i.Name
	$VMOprs = $i.OperatingSystem.Name
 
	IF ($VMName -like "VM*")
		{
			IF ($VMName -eq "VMM")
				{
					#
				}
			ELSE
				{
					add-content -path “C:\VMList.txt” -value $VMName	
					add-content -path “C:\VMList.txt” -value $VMOprs
					add-content -path “C:\VMList.txt” -value ‘‘
					$vmcount=$vmcount+1;
				}
		}
 
	IF ($VMName -like "VX*")
		{
			add-content -path “C:\VMList.txt” -value $VMName
			add-content -path “C:\VMList.txt” -value $VMOprs
			add-content -path “C:\VMList.txt” -value ‘‘
			$vxcount=$vxcount+1;
		}
}
 
write-host You have $vxcount VXs and $vmcount VMs.
$total=$vxcount+$vmcount
write-host Total: $total

We have two type of Virtual Machines called VM and VX. I listed them separately. But I have a machine called VMM, so I excluded that virtual machine.


Comments (1)

helen

September 17th, 2010
11:49:31

could you change this to list all vm and which host they are running on



Leave a Reply