Created
February 1, 2013 16:58
-
-
Save ddhahn/4692572 to your computer and use it in GitHub Desktop.
Get a file from a servers in a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function WriteLog($info, $errormsg=$false) | |
{ | |
#Funtion will write log entries along with a time and date stamp | |
$nowdate = date -format G | |
if ($errormsg) { | |
Write-Host "[$nowdate] $info" -foregroundcolor Red | |
} | |
else { | |
Write-Host "[$nowdate] $info" | |
} | |
"[$nowdate] $info" | out-file "c:\temp\gatherlogs.txt" -enc ASCII -append | |
} | |
#serversfile is a text file containing the list of servers to be updated. All | |
#server names are separated by CRLF | |
$serversfile = "C:\temp\servers.txt" | |
#get the contents of the servers file | |
$servers = get-content($serversfile) | |
foreach ($server in $servers) | |
{ | |
writelog "-------------------------------" | |
#verify that the server is up by pinging it | |
$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$server'" | Select-Object StatusCode | |
#if the statuscode property is 0, the ping succeeded. | |
if ($PingStatus.StatusCode -eq 0) { | |
WriteLog "Copying file from $server" | |
if ($server -ne "TPALICENSE"){ | |
copy "\\$server\c$\adskflexbackup\logs\debug.log" -destination "c:\temp\debuglogs\$server-debug.log" -ErrorVariable $copyerror | |
} | |
else { | |
copy "\\$server\d$\adskflexbackup\logs\debug.log" -destination "c:\temp\debuglogs\$server-debug.log" -ErrorVariable $copyerror | |
} | |
if ($copyerror.count -ne 0) { | |
writelog "Got log OK from $server" | |
} | |
else { | |
writelog "ERROR: could not get log from $server" | |
} | |
} | |
} | |
writelog "Script Ending Normally." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment