I need to pull up a bunch of information for the VMs living in specific datacenters within a vCenter (5.1, ugh) environment right now. There are three datacenters with clusters within each (plus some hosts not in clusters, but still within the datacenter items). With about 4000 VMs total, I really need a solid way to pull the information from just one datacenter, or even from a single cluster/host within each set. The first target is the smallest, with only 18 hosts and 111 VMs listed in the summary of the DC.
I've found some scripts to pull the information (or a good chunk of it) but I really need it to be more specific (instead of shotgunning to everything).
Information I really need to pull:
VM name (obviously)
vNIC with portgroup connected to, plus how many of them (if more than one at least) along with the adapter type selected (e1000, etc.)
VMDK information including how many and which datastore it's on as well as what the type of datastore it is (VMFS, NAS, etc.).
Snapshot if present (I'd also prefer to have the total snapshot size if easy, but I can always gather that later).
Affinity rule(s) applied against the VM(s). If this can include which rule is applied, that would be great.
IMO, easy stuff to add would be the OS inside the VM, IP address, and power state. I'd also like to have the location information for the VM. Such as which datacenter, cluster and host. Or at least have that available and either enabled or disabled easily (add/remove # in front of the lines).
I've been asked to get all of this for the first target before end of the week. I'd like to have it sometime before EOD tomorrow. One of the scripts I found earlier today is still runnning.
Get-VM | Select-Object Name, Powerstate, NumCPU, MemoryGB, @{N="Noofdisk"; E={($_ | Get-HardDisk).count}}, HardDisks, @{N="Datastore"; E={($_ | Get-Datastore).Name}}, @{N="DiskState"; E={($_ | Get-HardDisk).storageformat}}, ProvisionedSpaceGB, @{N="Snapshot"; E={($_ | Get-snapshot).count}}, VMHost, @{N="OS"; E={$_.ExtensionData.summary.config.guestfullname}} | Export-Csv -NoTypeInformation -UseCulture -Path "C:\powercli_reports\Inventory4Result.csv$(Get-Date -f MM-dd-yyyy-H-mm-ss).csv"
The above script just finished and pulled up all the info listed in it (good sign). Can I simply add "NetworkAdapter," to the list to get the adapter type for each VM?? I'd still like to narrow down the target to just the DC/cluster I need to focus on (at each run time). Even if it means altering the script to be target specific. I'm also going to still need the rest of the info I listed above added to this. With each run taking over an hour (around 1-1/4 to 1-1/2 hours) it would be better. Especially when I can target a smaller group and get the results faster.
Hopefully someone will answer up soon (like LucD).
update: added the "Get-Datacenter ="<datacenter>" | " at the start to narrow it down. I can change it to a cluster later when I start hitting the one with over 3000 VMs in it (so it takes less time).
Still trying to figure out how to get the Network Adapter Type added to the list. I've tried added "@{N="NetworkAdapter"; E={($_ | Get-NetworkAdapter)}}" but it's not giving me the desired result...
Update2: changed the NIC line to "@{N="NetworkAdapter"; E={($_ | Get-NetworkAdapter).type}}" and that pulls the info needed for that section... Need to figure out how to add a NIC count line to this too (hope what I'm thinking will work, but will see).
Update3: I've managed to get almost everything needed. Except for a way to get the DRS affinity rule for any VMs they are applied against. Since this is going against a DC, is that just not possible? I'll consider pushing the script against a cluster tomorrow.
Message was edited by: golddiggie