src/Public/Start-ProcessTuner.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

Function Start-ProcessTuner{
    param (
        [Parameter(Mandatory=$false)] $Interval         = 3,
        [Parameter(Mandatory=$false)] $JobName          = "ProcessTuner",
        [Parameter(Mandatory=$false)] [Switch] $Backgound
    )
    Write-Host "Starting ..." -ForegroundColor cyan
    
    Stop-ProcessTuner | Out-Null

    Start-Job -Name $JobName {
        param($Interval, $Backgound)

        if(Get-Module ProcessTuner){
            Import-Module ProcessTuner -Force -Verbose:$false
        } else {
            Install-Module ProcessTuner -Force
            Import-Module ProcessTuner -Force -Verbose:$false
        }
        
        while ($true) {
            if(!$Backgound){ Clear-Host }
            Get-ProcessRules | Set-ProcessRules
            Start-Sleep -Seconds $Interval
        }

    } -ArgumentList $Interval, $Backgound | Out-Null

    if(!$Backgound){
        Get-Job $JobName | Receive-Job -Wait
    }else{
        Get-Job $JobName
    }
}