So I've never tried nesting for each loops, but I thought I needed to in order to achieve the results I want.
The purpose of this script is to loop through a list of servers and find a directory on each with *.log files.
If the files in each directory are older than 24 hours, then they should be moved to a backup directory on a centralized server for this purpose.
The problem I am finding is that the script apparently runs with no errors, but it also doesn't give me any results, in other words, nothing got moved or copied to the backup directory when I can clearly see modified times greater than the time frame I'm specifying & PS doesn't present me with any errors.
I don't know if I should be using pipes somewhere or not. Or what it is I'm fouling up on. It seems that the script is doing what I'm telling "telling" it to do, but I'm not "telling" it what I think I am?
$Servers = import-csv "C:\Scripts\WebSrvrs.csv" $Hours = "24" % ($server in $servers) { $a = gci "\\$($server.servername)\C$\WINDOWS\system32\LogFiles\TEST\*.log" % ($x in $a) { $time = ((get-date) - $x.LastWriteTime).Hour if ($time -gt $Hours -and $x.PsIsContainer -ne $true) { COPY-item $x -Destination "\\Backup01\IIS_LOGS\test\$($server.ServerName)" } } }