Helpful scripts of the day: HTML Overview of VMs and Datastores

Today’s helpful scripts are ready to use scripts that generate an overview of your VM’s and your Datastores and save it to a HTML file. Great for reporting purposes. Easy to modify to meet your needs. Give them a try:

Get-DatastoreSizes (Rename to .ps1)

This one shows datastores with Used Space in GB, Free Space in GB and % Free Space.

Export-VMs (Rename to .ps1)

This one shows vm’s with OS Name, Total Disk Size in GB and Memory Size in GB.

Enjoy! 

Hugo

19 thoughts on “Helpful scripts of the day: HTML Overview of VMs and Datastores”

  1. Hello from Germany! THX for your very usefull script! Excellent Job! I modified your script for my use a little bit but I can’t manage it to give me the Ip Adress of the VM. Can you give me a hint ? That would be very appreciated !
    Matthias

  2. Hi Matthias, and welcome to my blog!
    The IP-address can be found in $VM.Guest.IPAddress
    Note that it requires the VMware Tools to be installed and running to grab the values. In case of multiple IP’s, the property will contain an array with the IP-addresses.
    Hope this helps,
    Hugo

    »crosslinked«

  3. Hi Hugo! Thx for your quick reply. Well, I tried it like you said before, but I didn’t work. The output is==> System.String[]
    I guess that means, that the requested data is inside an array. How can I get the information out of the array??

    Matthias

  4. Matthias,
    Ah, I see what you mean.
    That’s a bit tricky, because you will have to loop through all values of the array and add a property for each one. Here’s how it goes:
    For ($i=0;$i -lt $VM.Guest.IPAddress.Length;$i++){Add-Member -InpuObject $myObj -MemberType NoteProperty -Name “IP$i” -Value $VM.Guest.IPAddress[$i]}
    Hope that works…

  5. Ah. One more mistake. It will only show one IP address column, because not all vms will have the IP1 or IP2 property. Heres a fixed version:
    For ($i=0;$i -lt 4;$i++){Add-Member -InputObject $myObj -MemberType NoteProperty -Name “IP$i” -Value $VM.Guest.IPAddress[$i]}

    The number 4 will cause each VM to have 4 IP properties, which will be blank if they have less IPs.

  6. Hugo,
    Yes that’s working! Good Job ! THX for your help! Any prefered position for *FOR* routine? So far it works, but I get only one IP Adress :-(
    Matthias
    BTW: it’s called ==> InputObject

  7. hi,

    for now i got:

    $VC = Connect-VIServer (Read-Host “VC Server”)
    $VMs = Get-VM | Where {$_.PowerState -eq “PoweredOn”}
    $myCol = @()
    ForEach ($VM in $VMs)
    {
    $myObj = “” | Select-Object Name, OS, DisksGB, MemGB, NumCpu
    $myObj.Name = $VM.Name
    $myObj.OS = $VM.Guest.OSFullName
    $myObj.DisksGB = [Math]::Round((($VM.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2)
    $myObj.MemGB = [Math]::Round(($VM.MemoryMB * 1MB / 1GB),2)
    $myObj.NumCpu = $VM.numCpu
    For ($i=0;$i -lt 4;$i++){Add-Member -InputObject $myObj -MemberType NoteProperty -Name “IP$i” -Value $VM.Guest.IPAddress[$i]}
    $myCol += $myObj
    }
    $myCol | Sort-Object Name | Export-Csv “VMs.csv” -NoTypeInformation

    Can we add the following:
    Hostname
    ToolsStatus
    ToolsVersion

    And maybe give a choice menu in the beginning:
    1. Report vm’s Powered On
    2. Report vm’s Powered Off
    3. Report all vm’s

    :)

  8. Hi Peeters,

    Thank you very much for sharing this – One problem I am having is that when I run the script from the VI Toolkit window, I get an “access denied” for the destination output file directory. Might you be able to tell me what I’m doing wrong?

    Thank you,

    Steve

Leave a Reply