简体   繁体   中英

How to pull last boot time (up time) from an Azure VM with Powershell

I'm having difficulties finding a good way to indefinitely define how long a VM has been running in azure without writing code that executes on the host of each VM. I'm trying to find a way to programmatically pull the up time or last boot time for several hundred VMs at once. Most of them should have app insights enabled and I've found this "Last boot" feature which is close enough because I can work backwards with that to determine the uptime. I was wondering if there's a way to pull this insights metric with PowerShell, or if there's a better way to pull uptime per vm so ultimately I can iterate through my list of VMs and record all of their uptimes.

应用洞察上次启动

As the comment mentioned, the VMs on the surface are read as regular computers, then you can query the CIM, just use -ComputerName parameter for remote computers.

Get-CIMInstance -Class Win32_OperatingSystem | Select-Object -Property LastBootUpTime

Reference - https://docs.microsoft.com/en-us/powershell/module/cimcmdlets/get-ciminstance?view=powershell-7.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM