0

Can't seem to concatenate these variables into a filepath within a loop. I have no issue doing it manually, however it seems as though when I run it through the loop it doesn't save the variable names from the array. All help is apprecaited!

$ComputerArray =@( )
$ComputerArray += get-adcomputer -filter * | FT name 
foreach ($Computer in $ComputerArray ) {
$MostRecentFolderName = Get-ChildItem \\$Computer\c$\users | sort LastWriteTime | select -last 1 | FT name
$GetChildItem = Get-ChildItem \\$Computer\c$\users\$MostRecentFolderName\Downloads -Filter '*.exe'
if ($ChildItem.count > 0) 
{
$ChildItem | out-file C:\Users\AlexE\Documents\Reports\Download Report\$Computer
}
}
Alexander Edwards
  • 772
  • 2
  • 7
  • 18

1 Answers1

2

Expanding on Mathias' comment above, Format-Table is a rendering of data that is really for end-user consumption at the console.

If you want to pull one (or more) properties from an object then use Select-Object. You can read more here: https://stackoverflow.com/a/34815046/5771128

Community
  • 1
  • 1
Charlie Joynt
  • 4,411
  • 1
  • 24
  • 46