2020-02-13 06:32:56 -05:00
|
|
|
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 {
|
2021-08-21 06:28:42 -04:00
|
|
|
Write-IcingaFileSecure -File $OutFile -Value $Result;
|
2020-02-13 06:32:56 -05:00
|
|
|
}
|
|
|
|
|
}
|