Hi there guys. I am a rookie in PS and i need some help of you.
I have this script below to copy files/folder from one location to a list of servers, and i have 2 problems. The firts is to put some king of error output to a log when the copy of a file is unsucessfull ou sucessfull, and the other is how to put all this in a file Log. Because sometime we must show the logs of the copied files to our custumers when something is goin wrong.
#Point the script to the text file
$Computers = Get-Content "C:\DEP\servers.txt"
# sets the varible for the file location ei c:\temp\ThisFile.exe
#$Source = Get-Content -path "C:\DEPLOYMENT\SOURCE1"
# sets the varible for the file destination
#$Destination = Read-Host "\edp\sit_swaf\work\patches\dm_patches\"
$rc = 0
$Destination = "\output\"
$date = (Get-Date -UFormat "%Y%m%d%H%M")+".log"
# displays the computer names on screen
$log = "C:\LOGS\copy_files.$date
foreach($path in $Computers)
{
Echo "########################################################################################" >> $log
Echo "`n########################################################################################" >> $log
Echo "Working with Server $Computers" >> $log
Copy-Item -Recurse -Path "C:\SOURCE1\*.*" -Destination \\$path\$Destination -Force
if ($rc - neq 0)
{
Echo "`n########################################################################################" >> $log
Echo "Copy files with error in $Computers" >> $log
}
Echo "`nCompleted Working with $server" >> $log
}
Echo "########################################################################################" >> $log
Could someone help me on this?
Regards,
osramos