# encoding: ascii
# api: powershell
# title: Get-VMHostVersions
# description: Use to get ESXi host versions
# version: 0.1
# type: module
# author: Clint Jones
# license: CC0
# x-poshcode-id: 3443
# x-archived: 2016-03-22T03:48:44
# x-published: 2013-05-30T14:26:00
#
#
#========================================================================
# Created on:   5/17/2012 2:03 PM
# Created by:   Clint Jones
# Organization: Virtually Genius!
# Filename:     Get-VMHostVersions
#========================================================================

#Import modules
Add-PSSnapin "Vmware.VimAutomation.Core"

#Path to the log files
$log = "C:\Scripts\VMware\Logs\hostversions.txt"

#Creates directory structure for log files
$pathverif = Test-Path -Path c:\scripts\vmware\logs
switch ($pathverif)
    {
        True    {}
        False   {New-Item "c:\scripts\vmware\logs" -ItemType directory}
        default {Write-Host "An error has occured when checking the file structure"}
    }

#Connect to VMware servers
$viserver = Read-Host "Enter VMware server:"
$creds = Get-Credential
Connect-ViServer -Server $viserver -Credential $creds

#Get the version number of the host
Get-VMHost | Select-Object Name, Version | Format-Table -AutoSize | Out-File -FilePath $log -Append
