Public/Get-WinComputerUptime.ps1

Function Get-WinComputerUptime{
    <#
        .SYNOPSIS
        Get windows computer uptime
 
        .DESCRIPTION
        This function return uptime for target windows computer.
        If do not define computer name, localhost will be choose as a target computer
 
        .EXAMPLE
        PS> Get-WinComputerUptime -ComputerName PC-01
        Days : 0
        Hours : 2
        Minutes : 17
        Seconds : 4
        Milliseconds : 85
        Ticks : 82240857730
        TotalDays : 0.0951861779282407
        TotalHours : 2.28446827027778
        TotalMinutes : 137.068096216667
        TotalSeconds : 8224.085773
        TotalMilliseconds : 8224085.773
    #>

    [CmdletBinding()]
    [OutputType([System.TimeSpan])]
    Param (
        [String]$ComputerName
    )

    if ([string]::IsNullOrEmpty($ComputerName)){
        $ComputerName = $env:COMPUTERNAME
    }

    Write-Verbose -Message "Fetching information from target computer ..."
    $uptime = (Get-Date) - (Get-CimInstance Win32_OperatingSystem -ComputerName $ComputerName).LastBootupTime

    Return $uptime
}