PoshCode Archive  Artifact [400ef12639]

Artifact 400ef12639937e3a52953bdb4c1bdf7dd58e836e111d433e4e278e66613959e9:

  • File Get-Uptime.ps1 — part of check-in [f622ba6816] at 2018-06-10 13:21:00 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: 3143
# x-archived: 2012-02-01T10:33:02
# x-published: 2012-01-05T07:06: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")
 	}
}