Moek
Moek

Reputation: 119

get-childitem into array and other problems

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-
  1. Why does it output 3 empty rows?

  2. 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

Answers (2)

mjolinor
mjolinor

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

Martin Brandl
Martin Brandl

Reputation: 59031

1.) Probably because its a hidden file / folder. You can get rid of it if you add another Wherecondition:

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

Related Questions