Private/Get-QuserIdleTime.ps1
<# .Synopsis This converts quser idletime to something useful. .Parameter QuserIdleTime The idle time, as returned by Quser. .Parameter AsDateTime Return as [datetime] instead of [timespan]. #> function Get-QuserIdleTime { [CmdletBinding()] [OutputType([timespan])] [OutputType([datetime])] [OutputType([void])] Param( [Parameter(Mandatory = $true)] [string] $QuserIdleTime, [Parameter()] [switch] $AsDateTime ) $QuserIdleTime = $QuserIdleTime.Replace('+', '.') if ($QuserIdleTime -as [int]) { $QuserIdleTime = "0:${QuserIdleTime}" } if ($QuserIdleTime -as [timespan]) { [timespan] $idleTime = $QuserIdleTime if ($AsDateTime.IsPresent) { $now = Get-Date return $now.Subtract($idleTime) } else { return $idleTime } } else { return $null } } |