FrinkTheBrave FrinkTheBrave - 4 years ago 257
PowerShell Question

Redirect powershell in batch file works to file but not to null

The following line of code (in a 'Administrator' cmd window on Windows 10) outputs the title of some open windows to the me.txt file, and not to the screen:

POWERSHELL "Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | Select-Object MainWindowTitle" 1>C:\me.txt

But the following line outputs to the screen, even though I say don't:

POWERSHELL "Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | Select-Object MainWindowTitle" 1>NUL

Any ideas?

And I know that there is no point to the command if I am not interested in the result...

[Update] The reason for doing this is because the first time the line is run, it takes almost a second longer than subsequent times, so I wanted to run it once up front to make subsequent times more consistent. In those subsequent runs I do look at the results :-)

Answer Source

Does this produce the expect result? Apologies cannot test as no admin

POWERSHELL "Get-Process | Where-Object {$_.MainWindowTitle -ne ''} | Select-Object MainWindowTitle | Out-Null"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download