Function Name: Get-Uptime

Function Name: Get-Uptime

# ——————————————-
# Function Name: Get-Uptime
# Calculate and display system uptime on a local machine or remote machine.
# ——————————————-
function Get-Uptime {
[CmdletBinding()]
param (
[string]$ComputerName = ‘localhost’
)

foreach ($Computer in $ComputerName){
$pc = $computername
$os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computername
$diff = $os.ConvertToDateTime($os.LocalDateTime) – $os.ConvertToDateTime($os.LastBootUpTime)

$properties=@{
‘ComputerName’=$pc;
‘UptimeDays’=$diff.Days;
‘UptimeHours’=$diff.Hours;
‘UptimeMinutes’=$diff.Minutes
‘UptimeSeconds’=$diff.Seconds
}
$obj = New-Object -TypeName PSObject -Property $properties

Write-Output $obj
}

}

2 Comments

  1. naturally like your website however you have to check the spelling on quite a few of your posts. Several of them are rife with spelling issues and I find it very troublesome to inform the reality on the other hand I¦ll certainly come again again.

Leave a Reply

Your email address will not be published.