rvruptime.psm1
Function Get-RvrUptime { <# .SYNOPSIS Returns the uptime of a computer .DESCRIPTION This function leverates the command Get-Uptime of PowerShell 6 or higher. If Windows PowerShell is used it will perform a WMI query to perform the task. .EXAMPLE PS C:\> <example usage> TODO #> [cmdletbinding()] param() # a nice verbose message Write-Verbose "$($MyInvocation.InvocationName) $( get-date -Format dd-MM-yyyy_hh:mm ): Starting " # Based on the PowerShell version use Get-Uptime or WMI if($PSVersionTable.PSEdition -eq 'Core' ){ Write-Verbose "$($MyInvocation.InvocationName) $( get-date -Format dd-MM-yyyy_hh:mm ): Using PS Core " # PS Version Core is used So we can return the result of Get-Uptime Get-Uptime -ErrorAction Stop } else{ # Asume Windows PowerShell 5 # Get the uptime [System.TimeSpan]$uptime = (get-date -ErrorAction Stop) - (gcim Win32_OperatingSystem -erroraction stop ).LastBootUpTime # return the uptime $uptime } Write-Verbose "$($MyInvocation.InvocationName) $( get-date -Format dd-MM-yyyy_hh:mm ): Ending " } |