Copy file to multiple servers

Hi Guys,

I have found this script that copy file to multiple servers:

{

This file contains the list of servers you want to copy files/folders to

$computers = Get-Content “C:\PS\Servers.txt”

This is the file/folder(s) you want to copy to the servers in the $computer variable

$source = “C:\PS\TestFile.txt”

The destination location you want the file/folder(s) to be copied to

$destination = "c$\ProgramData\TestFolder"

foreach ($computer in $computers) {
if ((Test-Path -Path \$computer$destination)) {
Copy-Item $source -Destination \$computer$destination -Verbose
} else {
“\$computer$destination is not reachable or does not exist”
}
}

}

Now when I copy file some of the servers are offline
How to export those offline servers to txt document?

Regards
Raf

This should work but not tried


# This file contains the list of servers you want to copy files/folders to
$computers = Get-Content "C:\PS\Servers.txt"

# This is the file/folder(s) you want to copy to the servers in the $computer variable
$source = "C:\PS\TestFile.txt"

# The destination location you want the file/folder(s) to be copied to
$destination = "c$\ProgramData\TestFolder\"

foreach ($computer in $computers) {
if ((Test-Path -Path \\$computer\$destination)) {
Copy-Item $source -Destination \\$computer\$destination -Verbose
} 

$text = "Computers that did not respond"

else {

$text = $text + "\\$computer\$destination is not reachable or does not exist"

}
}
$text | Export-Csv "c:\List.csv"
}

I have this 3 scripts that are working fine but now I need some help to connect toes in one



# Script 1 
# Checks if computer is Online or Offline

$ComputersList = Get-Content "C:\DBOffline.txt"
 


foreach ($Device in $ComputersList) { 
 
        if (test-Connection -ComputerName $Device -Count 1 -Quiet ) {  
         
            write-Host "$Device is Online " -ForegroundColor Green 
         
                    } else 
                     
                    { Write-Warning "$Device is Offline" 
             
                    }     
         
}


# Script 2
# Compares two different files by size and displays message 

$fileA = "Source File"

$fileB = "Destination File"


if(Compare-Object -ReferenceObject $(Get-Content $fileA).Length -DifferenceObject $(Get-Content $fileB).Length)


 {"files are different"}

Else {"Files are the same"}



# Script 3
# Copies file from repository to destination

# Computer list
$ComputersList = Get-Content "C:\DBOffline.txt"
 
# Source File
$source = "C:\Source.txt"
 
# Destination Location
$destination = "c$\ProgramData\Database\"
 
foreach ($computer in $ComputersList) {
if ((Test-Path -Path \\$computer\$destination)) {
Copy-Item $source -Destination \\$computer\$destination -Verbose
} else {
"\\$computer\$destination is not reachable or does not exist"
}
}




This is the goal:
Excel table with:
Installation | Computer Name | Status

1  First check if computer is online if not write update excel spreadsheet
2. If computer is online it will compare two different files
3. If files are that same no action needed and update excel spreadsheet
4. If files are different it will copy file from source to destination update excel spreadsheet
5. If copying fails it will update excel spreadsheet

Powershell is new to me so I will really appreciate you help here 

Regards
Raf