Clear all

Read a file on a server


Topic starter

Here is a simple custom tool that I use to pull a specific log file from remote servers.



$fileToCheck = "\\$computerName\admin$\folder\another_folder\file.log"

if (Test-Path $fileToCheck -PathType leaf) {
$theFile = Get-Content -Path $fileToCheck
Write-Host $theFile
} else {
$theFile = "Log file not found."
$theFile = $theFile + "============================"
Write-Host $theFile

Does the tool always read a specific log file or do you capture user input so they pick one or filter based on some criteria?

This particular tool always reads a specific log file, since we use that file quite a bit. We also mostly use this custom tool via the API. But we could ask the user for the file path via the GUI (and via the API), which would make it a more generic tool indeed. If I did that, I might want to force the file to be a text-based file, since I'm not sure what would happen if they tried to read an executable 🙂


We could also build a pre-processor that would give them a list of common paths and/or files to choose from. Good idea. If we start seeing a lot of tools being built to read files from servers, we might try to consolidate them into a single generic tool.

Topic Tags