VMware Cloud Community
Guv
Enthusiast
Enthusiast

List all VM's in a virtual centre running windows XP OS

Is it possible to get a script which will list all VM's in a virtual centre which is running windows XP OS.  And also which vmware datacentre they are in.

That would be great to have in a csv format

Reply
0 Kudos
5 Replies
iamamit
Enthusiast
Enthusiast

This should help in exactly what you want.. Just you need to work on CSV file alignment little-bit.. Smiley Happy

http://www.techiessphere.com/2017/02/managing-guest-os-software-or-database-license-inventory-using-...

Refer the to the command section of this article (Step-3).

Get-VM | select Name, Guest | Export-CSV D:\test.csv

It should do for you. I am not sure if Datacentre column can be fit in the report.. will try and let you know..

Thanks,

Amit

Reply
0 Kudos
iamamit
Enthusiast
Enthusiast

Ok, so here is the command you can use to get the VM Name, Guest OS Details and Datacenter Details...

Get-VM | Select Name, Guest, @{N="Datacenter";E={Get-Datacenter -VM $_}}


To export the result in CSV, you can use it like below:


Get-VM | Select Name, Guest, @{N="Datacenter";E={Get-Datacenter -VM $_}} | Export-Csv D:\Test.CSV

Thanks,

Amit

Reply
0 Kudos
Guv
Enthusiast
Enthusiast

Thanks for the replies.

Is there anyway we can list out only the VM's with windows XP OS, as the above scripts lists out all VM's

Reply
0 Kudos
LucD
Leadership
Leadership

Try like this

Get-VM |

where{$_.Guest.OSFullName -match "XP"} |

Select Name,@{N='GuestOS';E={$_.Guest.OSFullName}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
iamamit
Enthusiast
Enthusiast

You may try below one, should work for filtering only "Windows Xp" guest VMs.

--------------------------------------------------------------------------------------------------------------------------

$vms = Get-VM

Foreach ($vm in $vms){

     if ((Get-View $vm).Guest.GuestFullName -match "windows xp"){

               Write-Host $vm.Name, " => " , (Get-View $vm).Guest.GuestFullName

     }

}

--------------------------------------------------------------------------------------------------------------------------


You can check keeping "Xp" instead of "Windows Xp", it should also work..


Thanks,

Amit

Reply
0 Kudos