mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
31 lines
907 B
PowerShell
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;
|
|
}
|