<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>get ESXi server uptime Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/get-esxi-server-uptime/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/get-esxi-server-uptime/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Sat, 09 Apr 2022 23:31:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Get ESXi Server Uptime Using Powershell and PowerCLI</title>
		<link>https://thesysadminchannel.com/get-esxi-server-uptime-using-powershell-and-powercli/</link>
					<comments>https://thesysadminchannel.com/get-esxi-server-uptime-using-powershell-and-powercli/#respond</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Sat, 09 Apr 2022 08:37:41 +0000</pubDate>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[get ESXi server uptime]]></category>
		<category><![CDATA[get-vmhost]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=3380</guid>

					<description><![CDATA[<p>If you manage a VMware environment it might be helpful to know how to get ESXi server uptime. You may notice that there is a simple way to check uptime via the browser, but that only works on a handful&#8230; <a href="https://thesysadminchannel.com/get-esxi-server-uptime-using-powershell-and-powercli/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/get-esxi-server-uptime-using-powershell-and-powercli/">Get ESXi Server Uptime Using Powershell and PowerCLI</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you manage a VMware environment it might be helpful to know how to get ESXi server uptime.  You may notice that there is a simple way to check uptime via the browser, but that only works on a handful of hosts.<br />
&nbsp;</p>
<p>What if you wanted to check 1000? 10,000?  Doing this manually is not going to scale very well so today we&#8217;re going to share how to get ESXi Server uptime using Powershell and PowerCLI.</p>
<div id="tableofcontents">
<h2>Table Of Contents</h2>
<ul>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#powershellscript">Get ESXi Server Uptime Using Powershell and PowerCLI</a></li>
<ul>
<li><a href="#parameters">Script Parameters</a></li>
<li><a href="#examples">Examples and Usage</a></li>
</ul>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
</div>
<p>&nbsp;<br />
<a href="https://thesysadminchannel.com/wp-content/uploads/2022/04/VMware-Summary.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2022/04/VMware-Summary.png" alt="VMware Summary" width="815" height="334" class="aligncenter size-full wp-image-4073" /></a></p>
<div id="requirements" style="scroll-margin-top: 15px;"></div>
<h2>Requirements</h2>
<p>In order to make this work, there are a couple of requirements needed so let&#8217;s list them out here.<br />
&nbsp;</p>
<ul>
<li>PowerCLI module</li>
<li>Connection to vCenter or ESXi host</li>
</ul>
<p>&nbsp;</p>
<div id="powershellscript" style="scroll-margin-top: 15px;"></div>
<h2>Get ESXi Server Uptime Using Powershell and PowerCLI</h2>
<p>Ideally, if you want to get the ESXi uptime status for more than 1 host, you&#8217;ll want to connect to a vCenter server. However, if you&#8217;re only checking 1 host, this script will work just fine.</p>
<p>With that said, let&#8217;s get to the script.</p>
<pre class="brush: powershell; title: ; notranslate">

Function Get-EsxiUptime {
&lt;#
.SYNOPSIS
    This script will get the current uptime for VMware ESXi Hosts

.NOTES
    Name: Get-EsxiUptime
    Author: theSysadminChannel
    Version: 1.0
    DateCreated: 2021-Aug-21

.LINK
    https://thesysadminchannel.com/get-esxi-server-uptime-using-powershell-and-powercli/ -
#&gt;

    [CmdletBinding()]
    param(
        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            Position = 0
        )]
        [Alias('Server', 'EsxiHost')]
        [string[]]    $VMHost
    )

    BEGIN {
        if (-not ($Global:DefaultVIServer)) {
            Write-Error &quot;Unable to continue.  Please connect to a vCenter Server.&quot; -ErrorAction Stop
        }
    }

    PROCESS {
        foreach ($EsxiServer in $VMHost) {
            try {
                $Server = Get-VMHost $EsxiServer -ErrorAction Stop
                if ($Server.PowerState -eq 'PoweredOn') {
                    $LastBoot = $Server.ExtensionData.Summary.Runtime.BootTime.ToLocalTime()
                    $Uptime = (Get-Date) - $LastBoot

                    [PSCustomObject]@{
                        VMHost   = $Server.Name
                        LastBoot = $LastBoot
                        UpTime   = ([String]$Uptime.Days + &quot; Days &quot; + $Uptime.Hours + &quot; Hours &quot; + $Uptime.Minutes + &quot; Minutes&quot;)
                        ConnectionState = $Server.ConnectionState
                    }
                } else {
                    [PSCustomObject]@{
                        VMHost   = $Server.Name
                        LastBoot = 'Unknown'
                        UpTime   = 'Unknown'
                        ConnectionState = $Server.ConnectionState
                    }
                }

            } catch {
                Write-Error $_.Exception.Message

            }
        }
    }

    END {}

}

</pre>
<p>&nbsp;</p>
<div id="parameters" style="scroll-margin-top: 15px;"></div>
<h2>Script Parameters</h2>
<h3>    -VMHost</h3>
<p>DataType: string/array<br />
Alias: Server, EsxiHost<br />
Description: Specify the ESXi server you would like to query.<br />
&nbsp;</p>
<div id="examples" style="scroll-margin-top: 15px;"></div>
<h3>Example 1 &#8211; Specify a list of servers separated by a comma</h3>
<pre class="brush: powershell; gutter: false; title: ; notranslate">
PS C:\&gt; Get-EsxiUptime -VMHost esxi1.ad.thesysadminchannel.com, esxi2.ad.thesysadminchannel.com
</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2022/04/Get-ESXi-Uptime-Example-1.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2022/04/Get-ESXi-Uptime-Example-1.png" alt="Get ESXi Uptime Example 1" width="820" height="222" class="aligncenter size-full wp-image-4080" srcset="https://thesysadminchannel.com/wp-content/uploads/2022/04/Get-ESXi-Uptime-Example-1.png?v=1649490407 886w, https://thesysadminchannel.com/wp-content/uploads/2022/04/Get-ESXi-Uptime-Example-1-768x208.png?v=1649490407 768w" sizes="(max-width: 820px) 100vw, 820px" /></a><br />
&nbsp;</p>
<h3>Example 2 &#8211; Using the pipeline</h3>
<pre class="brush: powershell; gutter: false; title: ; notranslate">
PS C:\&gt; Get-VMHost esxi* | Get-EsxiUptime
</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2022/04/Get-ESXi-Uptime-Example-2.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2022/04/Get-ESXi-Uptime-Example-2.png" alt="Get ESXi Uptime Example 2" width="820" height="203" class="aligncenter size-full wp-image-4083" srcset="https://thesysadminchannel.com/wp-content/uploads/2022/04/Get-ESXi-Uptime-Example-2.png?v=1649490923 892w, https://thesysadminchannel.com/wp-content/uploads/2022/04/Get-ESXi-Uptime-Example-2-768x190.png?v=1649490923 768w" sizes="(max-width: 820px) 100vw, 820px" /></a><br />
&nbsp;</p>
<div id="conclusion" style="scroll-margin-top: 15px;"></div>
<h2>Conclusion</h2>
<p>I suppose it would have helped if I had ESXi1 host powered on, but I thought it would be good to show what the expected output is for a machine that&#8217;s offline. Hopefully this script to get Esxi Uptime using Powershell and PowerCLI was helpful for you to see how quickly and easily you can scale this across multiple servers. I personally like how it receives pipeline input so you can use the native Get-VMHost command that you&#8217;re probably already familiar with.<br />
&nbsp;</p>
<p>If you liked this script, be sure to check out a similar script to <a href="https://thesysadminchannel.com/get-reboot-history-using-powershell/" rel="noopener" target="_blank">Get Reboot History Using Powershell</a>.  It can definitely come in handy for Windows environments.</p>
<p>The post <a href="https://thesysadminchannel.com/get-esxi-server-uptime-using-powershell-and-powercli/">Get ESXi Server Uptime Using Powershell and PowerCLI</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/get-esxi-server-uptime-using-powershell-and-powercli/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3380</post-id>	</item>
	</channel>
</rss>
