I am attempting to archive log files on a group of servers after the files are older than 10 days. If I run the portion of the code to filter the files on each server, I get an accurate list. When I run the entire script, the files on only the last server in the list are archived. I have spent hours trying to get this to work.
Thanks!
$Servers = Get-Content C:\Scripts\Scripts\FUTS\FutsServers.txt
$path = "\\$Server\C$\AppLogs\FUTS-PM\"
$destpath = "\\$Server\C$\AppLogs\FUTS Archive\"
$datestring =(Get-Date -UFormat "%Y%m%d")
ForEach ($Server in $Servers)
{
Get-ChildItem -Path "\\$Server\C$\AppLogs\FUTS-PM\*" |
Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-10)}}
ForEach ($Server in $Servers){
Compress-Archive -Path $path -CompressionLevel Fastest -DestinationPath "$destpath$datestring"
}