VMware Cloud Community
shankarg
Contributor
Contributor

HOw to generate reports using VI TK

Hi All,

I am want to generate a report of my datastores using vi tk.

tried using the hash table like

$Data = @{Datastores = (get-datastore)}

$storename = $data.datastore | select Name

$storefree = $data.datastore | select FreespaceMB

$storecap = $data.datastore | select CapacityMB

when i try to plot this data in a excel sheet i am not getting any thing and when i checked on the screen i am not getting all the variable values ..

i get only $storename displayed on the screen..

can some one help me on this ......

0 Kudos
5 Replies
halr9000
Commander
Commander

Just use get-datastore by itself or in combination with export-csv. Seems the data is already in the format you want it.

Get-Datastore | export-csv filename.csv

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
aw443
Contributor
Contributor

Hal, is it possible to get this outputted on a Per Cluster basis?

I can run this separately for each cluster, but I've been trying to just write one code that will run the get-datastore against all clusters (I have 6 clusters), and output it so the datastore freespace and capacity are both listed for each datastore, under the corresponding cluster.

I'm having trouble nesting the get-datastore into a get-cluster phrase. Or is there a better way to do this?

0 Kudos
admin
Immortal
Immortal

The complication with what you're trying to do is that datastores don't really belong to clusters, but to hosts. What you can do is to get a report to shows all datastores that belong to all hosts in a given cluster. This is pretty easy to do using my join-object routine. Since it's a given that the forum won't format the code properly, please see the attached file, DatastoresByCluster.ps1. The output for me was:

Cluster Name        Datastore Name      Datastore CapacityM Datastore FreeSpace
                                                          B                  MB
------------        --------------      ------------------- -------------------
New Cluster         datastore1                       134912               38094
New Cluster         GSS_IT_PROD                      547328              285160
New Cluster         33GB_shared                       68608               12459
New Cluster         200GB_Shared                     204544               62247

0 Kudos
aw443
Contributor
Contributor

This is wonderful. And yes, I understand its better approaching it on a per-host basis as datastores belong to hosts not clusters. This script provides a great output. I have one question however. It lists each LUN twice -- I'm assuming this is because I have 2 HBA's in each ESX host that can both see the same LUNs (multipathing).

Is there anyway to only list the LUN once?

Also, I added a "sort-object name", so it lists the LUNS by name.

0 Kudos
admin
Immortal
Immortal

This is wonderful. And yes, I understand its better approaching it on a per-host basis as datastores belong to hosts not clusters. This script provides a great output. I have one question however. It lists each LUN twice -- I'm assuming this is because I have 2 HBA's in each ESX host that can both see the same LUNs (multipathing).

Is there anyway to only list the LUN once?

Also, I added a "sort-object name", so it lists the LUNS by name.

I think the duplication is a bug, I saw duplicates in my environment and I don't use anything fancy like multipath. I filed a bug on the issue. In my case, using -unique worked around the issue. My environment is easier than your (I only have 1 cluster), so that may have helped.

0 Kudos