I have a function:
function Find-FooBars
{
[CmdletBinding()]
[OutputType([array])]
param
(
[string]$appname,
[string]$eventsId
)
$machines = @("server1", "server2")
$rx = -join ($eventsId, "_.*\.json")
$answer = [System.Collections.ArrayList]@()
foreach ($machine in $machines)
{
$dir = -join ("\\", $machine, "\c$\Applications\", $appname, "\logs\alerts")
$arr = Get-ChildItem $dir -Recurse |
Where-Object { $_.Name -match $rx } |
Select-Object @{ n = 'LastWriteTime'; e = { $_.LastWriteTime } }, @{ n = 'FullName'; e = { $_.FullName } }
$answer.Add($arr)
}
$answer | Sort-Object -Property LastWriteTime
}
When I invoke the function:
Find-FooBars FooBarMaker 123456
This is the output:
0
1
LastWriteTime FullName
------------- --------
11/14/2021 10:30:09 \\server2\c$\Applications\FooBarMaker\logs\alerts\123456_2021-11-14-153008Z_New_1636903809040.json
11/14/2021 21:00:53 \\server2\c$\Applications\FooBarMaker\logs\alerts\123456_2021-11-15-020018Z_Update_1636941653674.json
11/15/2021 10:30:09 \\server2\c$\Applications\FooBarMaker\logs\alerts\123456_2021-11-15-153008Z_Update_1636990209129.json
11/15/2021 20:20:08 \\server1\c$\Applications\FooBarMaker\logs\alerts\123456_2021-11-16-012008Z_Update_1637025608823.json
11/15/2021 23:50:08 \\server1\c$\Applications\FooBarMaker\logs\alerts\123456_2021-11-16-045007Z_Update_1637038208704.json
I would like to get rid of the 0
and 1
at the beginning the output.
[ Edit: There were 2 other questions identified as possible duplicates that talked about indices being inserted into an Array, but I did not see extra values in my ArrayList. My array held just what I expected. But I did see what seemed like spurious extra Console output I wanted gone. ]