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
}

}

13 Comments

  1. you are really a good webmaster. The site loading speed is amazing. It seems that you are doing any distinctive trick. In addition, The contents are masterwork. you have performed a wonderful activity on this subject!

Leave a Reply

Your email address will not be published.