I want to add "open in tail mode" to the windows text file context menu using power shell, the power shell script is ready and working but how do I add it and link it to context menu ?
Tried several guides online with no success other tools you need to open and select the file and are abit overkill.
the PowerShell basic script to add some color to make it more readable:
do {
get-content $logfile -wait -tail 1 | ForEach-Object {
switch -Regex ($_) {
"\[ERROR\]" { Write-Host $_ -ForegroundColor Red }
"\[DEBUG\]" { Write-Host $_ -ForegroundColor Yellow }
"\[INFO\]" { Write-Host $_ -ForegroundColor White }
"\[WARNING\]" { Write-Host $_ -ForegroundColor Blue }
Default { Write-Host $_ -ForegroundColor White }
}
}
} while ($false) # dummy loop so that `break` can be used.
Save the content bellow as a .reg file and execute it to create the context menu for log file extentions. Put the real path of your script
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Classes\.log]
@="Log.File"
[HKEY_CURRENT_USER\SOFTWARE\Classes\Log.File\shell\OpenTailMode]
@="Open in Tail mode"
[HKEY_CURRENT_USER\SOFTWARE\Classes\Log.File\shell\OpenTailMode\command]
@="PowerShell -File \"C:\\temp\\MyScript.ps1\" %1"
The %1 will be the log file right clicked that will be passed as argument to your PowerShell Script, so add this line at the beginning of your script:
$logfile = $Args[0]