icinga-powershell-framework/lib/core/icingaagent/finders/Find-IcingaAgentObjects.psm1
2020-02-13 12:32:56 +01:00

40 lines
939 B
PowerShell

function Find-IcingaAgentObjects()
{
param(
$Find = @(),
$OutFile = $null
);
if ($Find.Length -eq 0) {
throw 'Please specify content you want to look for';
}
[array]$ObjectList = (Get-IcingaAgentObjectList).Split("`r`n");
[int]$lineIndex = 0;
[array]$Result = @();
foreach ($line in $ObjectList) {
if ([string]::IsNullOrEmpty($line)) {
continue;
}
foreach ($entry in $Find) {
if ($line -like $entry) {
[string]$ResultLine = [string]::Format(
'Line #{0} => "{1}"',
$lineIndex,
$line
);
$Result += $ResultLine;
}
}
$lineIndex += 1;
}
if ([string]::IsNullOrEmpty($OutFile)) {
Write-Output $Result;
} else {
Set-Content -Path $OutFile -Value $Result;
}
}