Powershell script to be called by serveral servers to copy log files to remote location

1

We have several servers that save log files locally and I'm trying to automate logging to a single network location with a name of the parent folder where log files are stored and date modified time stamp

Server 1 D:\Projects\Ohio\(Rel1)\BuildScripts\logs

Server 2 D:\Projects\Ohio\(Rel2)\BuildScripts\logs

Server 3 D:\Projects\Ohio\(Rel3)\BuildScripts\logs

Trying to copy all logs to R:\Logs\CruiseControl\(Rel.AW) \logs+timestamp\logfiles.txt

So far I'm able to set this up for Server 1 with the script below but the problem is that the same script needs to be called by Server 1, Server 2 and Server 3 and each time logs need to go to specific stream (Rel1, Rel2, Rel3) How can I reference the stream name ?

$logDir = 'D:\Projects\Ohio\Rel.AW\BuildScripts\logs'
$copyDir = 'R:\Logs\CruiseControl\Rel.AW'

Get-ChildItem $logDir -File | ForEach {
    $parentFolder = $_.Directory.Name
    $timeStamp = $_.LastWriteTime.ToString('MMddyyyy')
    $path = Join-Path -Path $copyDir -ChildPath "$($parentFolder)_$($timeStamp)"
    Write-Host "Path to copy to is: $path" -ForegroundColor Green
}
robocopy $logDir $path /log+:R:\Logs\CruiseControl\Rel.AW\log

alexserd

Posted 2015-08-14T21:36:38.787

Reputation: 11

Answers

0

PowerShell 3.0-5.0: PowerShell Workflows: The Basics

Workflow <workflow name> {
 foreach –parallel ($object in $objects){
   <code>    ...      </code>
 }
}

PowerShell 2 Job: Thread Ping

STTR

Posted 2015-08-14T21:36:38.787

Reputation: 6 180