Created
August 2, 2018 09:23
-
-
Save alexinnes/4a21f8d5400c9c0e3f669bbcf322abb0 to your computer and use it in GitHub Desktop.
Get System Uptime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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