when I use:
netstat -f | out-gridview
in PowerShell 7.3, I get the window but it has only one column which is a string. I don't know why it's not properly creating a column for each of the headings like Proto, Local Address etc. how can I fix this?

While commenter Toni makes a good point to use
Get-NetTCPConnection | Out-GridViewinstead, this answer addresses the question as asked.To be able to show output of
netstatin grid view, we have to parse its textual output into objects.Fortunately, all fields are separated by at least two space characters, so after replacing these with comma, we can simply use
ConvertFrom-CSV(thanks to an idea of commenter Doug Maurer).For a detailed explanation of the RegEx pattern used with the
-replaceoperator, see this RegEx101 demo page.This is the code of my original answer, which is functionally equivalent. I'll keep it as an example of how choosing the right tool for the job can greatly simplify code.