Scenario: You want to collect logs from various servers and place the copied logs into a single directory. Due to the log names being the same on each server, we want avoid overwriting existing logs. We also want to know the server from where each log was copied from.
Solution: The following will copy the IMAP logs from 4 servers into 1 local directory. Each file when copied to the directory will be renamed by prefixing the file with the server name. It will also add the counter to the end of the file.
$Servers = "ExSvr1","ExSvr2","ExSvr3","ExSvr4"
$servers | %{$File = Get-ChildItem -Path "\$_c$Program FilesMicrosoftExchange ServerV15LoggingIMAP4" -Recurse;$i=1;Foreach ($f in $File) {Copy-Item $f.FullName ("C:TempIMAPPOP$_" + $f.BaseName + $i +".log");$i++}}
#End