VMware Cloud Community
sg0133
Contributor
Contributor

VM inventory for multiple environments & multiple vCenters

Hi All ,

I wanted to gather details of multiple VMs distributed across four vCenters. I wanted to gather following below informations about the VMs

1:VMname
2:No of CPU
3:Memory
4:ProvisionedSpaceGB
5:UsedSpaceGB
6:ESXi Hostname
7:ESXi version on which the VM reside
8:Build
9:Server Manufacturer
10:Model of the server
11:Guest OS type

The input csv is having the VMnames with respective environment type like stage,test,dev,prod. Is there anyway the env type will also get reflected with the above details for the corresponding VMs.

The input file sample :
Name   Environment
abc-dev-mw-02  Development
abc-dev-vm-bld-01 Development
abc-stage-vm-tom-1 Stage
cdc-test-vm-qa-1 Test
abc-prod-vm-cor-1 Production
cdc-prod-vm-cor-1 Production

Currently i am using the below script for getting the output for the VMs located in multiple vCenters.Thanks for sharing the information for running script in multiple vCenter by Luc.

In this case the input file i manually sorted the VMs according to environment.
========================================================================

$vmlist = Import-CSV C:\Users\abc\Documents\input-dev.csv
$ExportPath = "C:\Users\abc\Documents\output-dev.csv"
$vms = get-vm $vmlist.Name
foreach ($item in $vmlist){
$usage = $vms |Select Name, NumCPU, MemoryMB, ProvisionedSpaceGB, UsedSpaceGB, @{N=”ESX Host”;E={Get-VMHost -VM $_|Select Name, Version,
     Build, Manufacturer, Model}}, @{N=”Datastore”;E={Get-Datastore -VM $_}}, @{N=”Guest OS”;E={Get-VMGuest -VM $_}}
}
$usage | Export-Csv $ExportPath -NoTypeInformation


It will be great help if anybody share thoughts in which the script can run and generate output with Environment details also.

Thanks in Advance.

Regards,
sg0133

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

Try something like this

$ExportPath = "C:\Users\abc\Documents\output-dev.csv"

$usage = foreach($item in (Import-CSV C:\Users\abc\Documents\input-dev.csv)){

    Get-VM -Name $item.Name |

    Select Name, NumCPU, MemoryMB, ProvisionedSpaceGB, UsedSpaceGB, @{N=”ESX Host”;E={Get-VMHost -VM $_|Select Name, Version,

     Build, Manufacturer, Model}}, @{N=”Datastore”;E={Get-Datastore -VM $_}}, @{N=”Guest OS”;E={Get-VMGuest -VM $_}},

     @{N='Environment';E={$item.Environment}}

}

$usage | Export-Csv $ExportPath -NoTypeInformation -UseCulture


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

sg0133
Contributor
Contributor

Thanks Luc. It's working perfectly.

Regards,

sg0133

Reply
0 Kudos