top of page

PowerShell PowerCLI Get-VMHost

Connect to vCenter, display all ESXI hosts

Get-VMHost

get-vmhost.png

Gets values requested From ESXI hosts and numeric formatting | out to grid

        
Get-VMHost | select-object Name, LicenseKey, state, connectionstate, powerstate, manufacturer, model, ProcessorType, NumCPU, @{l='CPUtotalMhz';e={("{0:N0}" -f $_.CPUtotalMhz)}}, @{l='CpuUsageMHz';e={("{0:N0}" -f $_.CpuUsageMHz)}} , @{l='MemoryTotalGB';e={($_.memorytotalGB).tostring("##.##")}},  @{l='MemoryUsageGB';e={($_.memoryUsageGB).tostring("##.##")}}, version | Out-GridView
        

Get-VMHost-Info.png

Quick review of firewall and services on ESXI hosts

Get-VMHost | Get-VMHostFirewallException | export-csv C:\Temp\Firewalls.csv

get-vmhost-firewall.png

Gets values requested From ESXI hosts and added some numeric formatting and math, and send via email.         
    <#

    PowerCLI 6.0 Load
    & 'C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

    PowerCLI 6.5 Load
    & 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

    #>

    Remove-Item "C:\temp\MyHTMLFile.html"

    & 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'

    $vCenter="YourvCenterServer"
    $UserName="YourUsername"
    $Password="YourPassword"

    Connect-VIServer -Server $vCenter -Protocol https -User $UserName -Password $Password

     $MyHosts=  Get-VMHost | Select Name, ConnectionState, Version, Build,@{l='RAM Total GB';e={($_.MemoryTotalGB).tostring("#.##")}}, @{l='RAM Usage GB';e={($_.MemoryUsageGB).tostring("#.##")}}, @{l='RAM Free GB';e={($_.MemoryTotalGB - $_.MemoryUsageGB).tostring("#.##")}}, @{l='CPU Used GHz';e={($_.CPUUsageMHZ / 1000)}}, @{l='CPU Total GHz';e={($_.CpuTotalMhz / (1000))}} | Sort-Object Name

    # HTML/CSS style for the output file

    $head = " <style>"
    $head += "BODY{background-color:white;}"
    $head += "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse; width:1200px}"
    $head += "TH{border-width: 1px;padding:0px;border-style: solid;border-color: black;background-color:yellow}"
    $head += "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black}"
    $head += "</style>"


    # Write the output to an HTML file
    $myHosts | ConvertTo-HTML -Head $head -Body $strMail | Out-File C:\temp\MyHTMLFile.html

    # Mail the output file
    $msg = new-object Net.Mail.MailMessage
    $att = new-object Net.Mail.Attachment("C:\temp\MyHTMLFile.html")
    $smtp = new-object Net.Mail.SmtpClient("YourMailRelayHere")
    $msg.From = "YourEmail@Your.com"
    $msg.To.Add("YourEmail@Your.com")
    $msg.Subject = "ESXI Build Information"
    $msg.IsBodyHtml = 1
    $msg.Body = Get-Content C:\temp\MyHTMLFile.html
    $smtp.Send($msg)

    Disconnect-viserver -server $vCenter -Confirm:$False        
        
        

bottom of page