I am trying to create an array of Excel file basenames, as a string, to run through a foreach loop later in my script. I was able to generate the array but it includes the header “name” and is causing the script to error out. I am sure I did this in a goofy and more complicated way than needed.
$d = get-date -displayhint date $h = Get-ChildItem $connsource | Select-object -property name, lastwritetime | where-object {$_.LastWriteTime -ge ($d.adddays(-2))} | Select-object -property name | out-string $table = $h.replace(".xlsx","")
I want to be sure to only grab Excel files dated within the last 2 days. Not pretty but it works as far as stripping the file name down to the base name but I don’t know how to exclude the “Name” header when I call the $table variable. I think my issue is the last Select-Object before the out-string, but not sure and not sure how else to do this.
Thanks in advance for any help.