icinga-powershell-framework/lib/core/thread/New-IcingaThreadPool.psm1
2021-09-02 09:23:10 +02:00

31 lines
907 B
PowerShell

function New-IcingaThreadPool()
{
param(
[int]$MinInstances = 1,
[int]$MaxInstances = 5
);
$SessionConfiguration = $null;
$SessionFile = Get-IcingaJEASessionFile;
if ([string]::IsNullOrEmpty((Get-IcingaJEAContext))) {
$SessionConfiguration = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault();
} else {
if ([string]::IsNullOrEmpty($SessionFile)) {
Write-IcingaEventMessage -EventId 1502 -Namespace 'Framework';
return $null;
}
$SessionConfiguration = [System.Management.Automation.Runspaces.InitialSessionState]::CreateFromSessionConfigurationFile($SessionFile);
}
$Runspaces = [RunspaceFactory]::CreateRunspacePool(
$MinInstances,
$MaxInstances,
$SessionConfiguration,
$host
)
$Runspaces.Open();
return $Runspaces;
}