Get-Content -wait in -Command

Hi

I’m trying to create a one-liner to tail a logfile. I use this:
powershell -NoProfile -ExecutionPolicy Unrestricted -Command (get-content “D:\Test.txt” -Tail 10 -Wait)

The above command shows nothing but just hangs. If I try
powershell -NoProfile -ExecutionPolicy Unrestricted -Command (get-content “D:\Test.txt” -Tail 10)

It gives me the lines as intended.

Is this not possible or is there a trick?

Regards Lars

Hi, welcome back :wave:

Firstly, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

How to format code on PowerShell.org

Not sure why you wouldn’t just go with:

Get-Content 'D:\Test.txt' -Tail 10 -Wait

However, if you don’t want to use it that way, try braces instead of brackets:

powershell  -NoProfile -ExecutionPolicy Unrestricted -Command {Get-Content  'D:\Test.txt' -Tail 5 -Wait}
1 Like

Hi

Thanks.

The backets just outputs the PS command:

C:\Users\jcvi0017>powershell -NoProfile -ExecutionPolicy Unrestricted -Command {get-content 'D:\Test.txt' -Tail 10}
get-content 'D:\Test.txt' -Tail 10

And I don’t just enter the command, because of the way it should be spawned.
It will be very similar to if I asked; How to run/display

get-content "D:\Test.txt" -Tail 10 -Wait

directly from a .lnk file ?

Regards.

Are you running it from a CMD prompt or a PowerShell console?

This is what I use. Likely overkill, but it works. Leave the -Verb off is you dont want to run as admin:

%WINDIR%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Start-Process PowerShell -ArgumentList '-ExecutionPolicy ByPass -File D:\Test.PS1' -Verb RunAs