Last Reboot time for all Vm's

Veerpal Singh 31 Reputation points
2022-03-03T17:36:09.777+00:00

Looking for a Powershell script that can provide the Last reboot time of all the servers in Azure. Any other alternatives as well?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,035 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. kobulloc-MSFT 26,811 Reputation points Microsoft Employee Moderator
    2022-03-03T18:44:03.417+00:00

    Hello, @Veerpal Singh !

    Looking for a PowerShell script that provides all the reboot logs? I would use Get-AzureDeploymentEvent or Get-CimInstance with lastbootuptime.

    Get-AzureDeploymentEvent

    https://azure.microsoft.com/en-us/blog/viewing-vm-reboot-logs/

    To help determine whether the reboot you observed on your Virtual Machine is due to a Planned Maintenance event, we’re introducing a new API that provides logs that show when your VM was rebooted. This can be accessed in the Portal under "View Reboot Logs" or by running the following query in PowerShell:

    $today = get-date  
    $yest = $today.AddDays(-1)  
    Get-AzureDeploymentEvent -ServiceName kenaztestdemoservice -StartTime $yest -EndTime $today  
    

    179861-image.png

    Get-CimInstance

    https://devblogs.microsoft.com/scripting/powertip-get-the-last-boot-time-with-powershell/

    Another approach would be to use Get-CimInstance with LastBootUpTime:

    Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime  
    

    179852-image.png

    An approach used by Improve Scripting is to create a list of servers in a text file and then run the following:

    https://www.improvescripting.com/get-the-last-boot-time-using-powershell-script/

    Get-CimInstance -ComputerName (Get-Content -Path 'C:\Temp\servers.txt') -Class CIM_OperatingSystem -ErrorAction Stop | Select-Object CSName, LastBootUpTime | Out-GridView  
    

    Additional Options
    If you are still looking for more options, Shell Geek has a pretty good list of available approaches including net statistics workstation and system info (optionally using /S for server name):

    https://shellgeek.com/get-last-boot-time-of-computer-using-powershell

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.