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

Tagged with:
 

19 Responses to Helpful scripts of the day: HTML Overview of VMs and Datastores

  1. Alan says:

    Thats usefull, nice to publsih into an IIS site for manager/reporting type people to view the results

  2. sTyLeR_1 says:

    Hi Peeters,

    very nice! and tnx for the job. this saved me a lot of work :)

  3. admin says:

    You’re welcome.
    If you have any other scripting requests, please don’t hesitate to ask.
    Hugo

  4. Matthias says:

    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

  5. admin says:

    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«

  6. Matthias says:

    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

  7. admin says:

    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…

  8. admin says:

    DÓh, that should read inpuTobject.

  9. admin says:

    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.

  10. Matthias says:

    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

  11. admin says:

    Matthias, see my corrections in other comments. Put the code from comment 9 in the script before $myCol+=$myObj

    Hugo

  12. Matthias says:

    Great!
    It works!!! THX for your help!

    Have a nice day!

  13. sTyLeR_1 says:

    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

    :)

  14. J. Le says:

    what is the syntax to run this script against a Virtual Center?

  15. admin says:

    @J. Le
    Just type the full path to the script file in your Powershell window.

  16. Steve says:

    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

  17. admin says:

    @Steve
    Try replacing this:
    $output = Read-Host “Output path\file”
    With this:
    $output = ‘D:\scripts\output.html’ # Use your path here

  18. Steve says:

    Thank you so much! I can’t begin to tell you how significant your work has been in helping me to launch our vmware environment…

  19. admin says:

    @Steve
    Cool! Thank you for taking the time to comment on my website. I appreciate it.
    You’re welcome.
    Hugo

Leave a Reply