Collect a Log File From Multiple Machines

Today I needed to investigate a single log file on multiple machines from different sites – to achieve this, i used the following Powershell…

It reads a list of hostnames / machines then copys the log file from each to a central organised folder.

## Read a list of hostnames and attempt to gather a specific log file from each

## Path of the log file we want to gather - !!REPLACE!! will be replaced by the computername
$remoteLogFilePath = "\\!!REPLACE!!\c$\log.txt"

## Local working folder
$localFolderPath = "C:\Working\"

## List of Computers to Gather Log File From
$computers = get-content -Path "C:\computers.txt"

## Create a new directory in the working folder named todays date
$date = get-date -format m
$path = $localFolderPath + '\' + $date
new-item $path -ItemType directory

foreach ($computer in $computers)
$remotePath = $remoteLogFilePath -replace "!!REPLACE!!","$computer"
$localPath = $path + '\' + $computer + '.log'

copy-item -Path $remotePath -Destination $localPath

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s