Reputation: 119
I want to add every output from following code into an array:
Get-ChildItem "C:\Users\mime\Desktop\2_Import"| Where-Object {($_.lastwritetime -gt $date)} | select basename | ft -HideTableHeaders
Output:
-empty row-
10830
11042
-empty row-
-empty row-
Why does it output 3 empty rows?
I've tried out a few things and searched for a solution to get the numbers in an array, but nothing has worked. What can I do to address this?
Upvotes: 0
Views: 433
Reputation: 68341
You're over-complicating it with the Format-Table
. Try it this way:
Get-ChildItem "C:\Users\mime\Desktop\2_Import"| Where-Object {($_.lastwritetime -gt $date)} | select -expandproperty basename
Upvotes: 1
Reputation: 59031
1.) Probably because its a hidden file / folder. You can get rid of it if you add another Where
condition:
Get-ChildItem "C:\Users\mime\Desktop\2_Import" |
Where BaseName |
Where-Object {($_.lastwritetime -gt $date)} |
select basename |
ft -HideTableHeaders
2.) Just assign the output to a variable:
$myResultArray = Get-ChildItem "C:\Users\mime\Desktop\2_Import" |
Where BaseName |
Where-Object {($_.lastwritetime -gt $date)} |
select basename |
ft -HideTableHeaders
Upvotes: 0