Skip to content

Instantly share code, notes, and snippets.

@alexinnes
Created August 2, 2018 09:23
Show Gist options
  • Save alexinnes/4a21f8d5400c9c0e3f669bbcf322abb0 to your computer and use it in GitHub Desktop.
Save alexinnes/4a21f8d5400c9c0e3f669bbcf322abb0 to your computer and use it in GitHub Desktop.
Get System Uptime
function Get-Uptime {
<#
.Synopsis
gets the computers uptime in Days, Hours and Minutes
.DESCRIPTION
gets the computers uptime in Days, Hours and Minutes
.EXAMPLE
Get-Updtime -Computername <ComputerName>
.EXAMPLE
Get-Uptime #Gets the uptime of the local computer.
.INPUTS
-ComputerName Specify the name of the computer you want to check
#>
[CmdletBinding()]
Param (
# Specify the name of one or more computers
[Parameter(
Position = 0,
Mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
ParameterSetName = 'Computer'
)]
[Alias("Computer", "__SERVER", "IPAddress")]
$ComputerName = $env:COMPUTERNAME
)
Begin {
$LastReboot = Get-CimInstance -ComputerName $ComputerName -ClassName win32_operatingsystem | Select-Object csname, lastbootuptime
}
Process {
$TimeSpan = New-TimeSpan $LastReboot.lastbootuptime (get-date)
$output = [ordered]@{
Days = $timeSpan.Days
Hours = $timeSpan.Hours
Minutes = $timeSpan.Minutes
ServerName = $ComputerName
}
}
End {
return $output
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment