ps/Modules/Cole.PowerShell.Developer/Public/Get-WindowsThreadSliceTime.ps1

24 lines
825 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-WindowsThreadSliceTime {
<#
.SYNOPSIS
Used to determine the windows thread slice time. Useful for Invoke-JobRunner
#>
[CmdletBinding(DefaultParameterSetName = 'Milliseconds')]
param (
[Parameter(ParameterSetName = "Milliseconds")]
[switch]$Milliseconds,
[Parameter(ParameterSetName = "Ticks")]
[switch]$Ticks
)
Add-Type -Assembly "System.ServiceModel.Internals"
$assembly = [System.AppDomain]::CurrentDomain.GetAssemblies().Where({ $_.GetName().Name -match 'System.ServiceModel.Internals' })
$timer = $assembly.GetTypes().Where({ $_.Name -eq 'IOThreadTimer' })
$timerValue = $timer.GetProperty("SystemTimeResolutionTicks").GetValue($null)
if ($Milliseconds) {
return $timerValue / 10000
} else {
return $timerValue
}
}