Get the contents of a remote file

Invoke-Command -ComputerName <servename> -ScriptBlock {
set-location <PathToFile>
#i am choosing the newest file in the folder according to the timestamp property
$a = get-childitem | Sort-Object CreationTime -Descending | Select-Object Name -First 1
write-host “$($ on $(hostname)” -BackgroundColor Red
#here i need the last 3 lines of the log file
Get-Content $ -Tail 3

Leave a Reply

Your email address will not be published.