PowerShell for Windows Admins

Dec 2 2017   4:52AM GMT

Hyper-V VM start time

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Hyper-V
Powershell

Its fairly easy to see how long a VM has been running – but how do you know the Hyper-V VM start time?

In Hyper-V the VM uptime is easy to find

PS> Get-VM | where State -eq 'Running'

Name        State CPUUsage(%) MemoryAssigned(M) Uptime          Status             Version
----       ----- ----------- ----------------- ------           ------             -------
W16AS01    Running 6         1246              00:12:18.6480000 Operating normally 8.0
W16CN01    Running 0         538               00:09:18.2180000 Operating normally 8.2
W16DC01    Running 0         940               00:15:19.1550000 Operating normally 8.0
W17035CN01 Running 0         540               00:06:17.7980000 Operating normally 8.2
W1709CN01  Running 0         512               00:03:15.8540000 Operating normally 8.2

Sometimes you might want to know when the VM was started

The Uptime property is a TimeSpan so you can calculate the start time

PS> $now = Get-Date
PS> Get-VM | where State -eq 'Running' | select Name, @{N='StartTime'; E={$now - $_.Uptime}}

Name       StartTime
----       ---------
W16AS01    02/12/2017 10:23:15
W16CN01    02/12/2017 10:26:16
W16DC01    02/12/2017 10:20:15
W17035CN01 02/12/2017 10:29:16
W1709CN01  02/12/2017 10:32:18

Once you’ve added the calculated property you can use like any other property

PS> Get-VM | where State -eq 'Running' | select Name, @{N='StartTime'; E={$now - $_.Uptime}} | sort StartTime

Name       StartTime
----       ---------
W16DC01    02/12/2017 10:18:46
W16AS01    02/12/2017 10:21:47
W16CN01    02/12/2017 10:24:47
W17035CN01 02/12/2017 10:27:48
W1709CN01  02/12/2017 10:30:50

Using calculated fields like this is a handy technique for changing the way data is displayed.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: