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
}
}