PoshCode Archive  Artifact [f517a5090f]

Artifact f517a5090f875b022388b236f3125411ba560324f2fe64f1993980a89fb08dda:

  • File Get-Uptime.ps1 — part of check-in [1b30accbbd] at 2018-06-10 13:37:19 on branch trunk — Function to report uptimes for single/multiple hosts as objects. Useful if not very original. (user: 81stPerson size: 1339)

# encoding: ascii
# api: powershell
# title: Get-Uptime
# description: Function to report uptimes for single/multiple hosts as objects. Useful if not very original.
# version: 1.00
# type: function
# author: 81stPerson
# license: CC0
# function: Get-Uptime
# x-poshcode-id: 4136
# x-archived: 2013-06-19T16:32:32
# x-published: 2013-04-29T13:32:00
#
#
Function Get-Uptime {
<#
.SYNOPSIS 
	Displays Uptime since last reboot
.PARAMETER  Computername
.EXAMPLE
 Get-Uptime Server1
.EXAMPLE
 "Server1", "Server2"|Get-Uptime
.EXAMPLE
 (Get-Uptime Sever1)."Time Since Last Reboot"
#>
 [CmdletBinding()]
 Param (
 [Parameter(Mandatory=$True,ValueFromPipeline=$true,Position=0)]
	[STRING[]]$Computername
	)

 Begin {Write-Verbose "Version 1.00"}
	
 Process {
 	$Now=Get-Date
 	$LastBoot=[System.Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject win32_operatingsystem -ComputerName $computername).lastbootuptime)
 	$Result=@{ "Server"=$($Computername);
 	    	   "Last Reboot"=$LastBoot;
 	    	   "Time Since Reboot"="{0} Days {1} Hours {2} Minutes {3} Seconds" -f ($Now - $LastBoot).days, `
 			($Now - $LastBoot).hours,($Now - $LastBoot).minutes,($Now - $LastBoot).seconds}
 	Write-Output (New-Object psobject -Property $Result|select Server, "Last Reboot", "Time Since Reboot")
 	}
}