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' $localPath copy-item -Path $remotePath -Destination $localPath }