Skip to content

Instantly share code, notes, and snippets.

@kpatnayakuni
Last active December 29, 2019 06:21
Show Gist options
  • Select an option

  • Save kpatnayakuni/84760da95ba55414e83184474d8b70ec to your computer and use it in GitHub Desktop.

Select an option

Save kpatnayakuni/84760da95ba55414e83184474d8b70ec to your computer and use it in GitHub Desktop.
Function Get-LastRebootTime
{
[CmdLetBinding()]
param
(
[parameter(Mandatory)]
[string] $ResourceGroupName,
[string] $VMName
)
if (-not ($VMName))
{
$VMList = Get-AzVM -ResourceGroupName $ResourceGroupName
}
else
{
$VMList = Get-AzVM -ResourceGroupName -Name $VMName
}
$Output = @()
$Output += foreach ($VM in $VMList)
{
$ComputerInfo = Get-CimInstance -ClassName CIM_OperatingSystem -Property 'LastBootUpTime' -ComputerName $VM.Name
New-Object -TypeName psobject -Property @{
ComputerName = $VM.Name
$LastRebootTime = $ComputerInfo.LastBootUpTime
}
}
return $Output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment