stash/Get-Uptime.ps1
function Get-Uptime { [CmdletBinding()] param( [Parameter()][Switch]$Since ) process { New-Delegate ntdll { int NtQuerySystemInformation([int, buf, int, buf]) } $buf = [Byte[]]::new(0x30) # sizeof(SYSTEM_TIMEOFDAY_INFORMATION) if (($nts = $ntdll.NtQuerySystemInformation.Invoke( 3, $buf, $buf.Length, $null )) -ne 0) { Write-Verbose (ConvertTo-ErrMessage -NtStatus $nts) return } $buf = Read-DataValues $buf -Map l3I2L2 ([DateTime]::FromFileTime($buf[0]), # Since [TimeSpan]::FromMilliseconds(($buf[1] - $buf[0]) / 10000) # uptime )[!$Since] } } |