'Writing output from netstat and findstr to text file

I am currently having a problem writing the output of a netstat and findstr command to a text file. The command works fine itself when not having it's output being written to a file (netstat -a | findstr "ESTABLISHED"), or when only the netstat command is used (netstat -a >> task3.txt).

This is the command I've written which does not write to the file: netstat -a | findstr "ESTABLISHED" >> task3.txt.



Solution 1:[1]

This will run in a windows cmd command line or batch-file. If you are on a supported Windows system, PowerShell is available.

powershell -NoLogo -NoProfile -Command ^
    "Get-NetTCPConnection | Where-Object { $_.State -eq 'Established' } >>'.\task9.txt'"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lit