Im fairly new with Powershell but loving every successful second My script is getting Active Listening ports from host. The script works fine without doing any formatting. Once I add Format_Table it will get through 5 or so host and then toss the below error.
The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence. This is likely caused by a user-specified
"format-table" command which is conflicting with the default formatting.
Each time you run Format-Table, it outputs a set of headers as well as data. Once you’ve started a table, you can’t run another Format-Table or you’ll get the error you’re getting. Without seeing where you were putting Format-Table, it’s tough to troubleshoot this for you, but generally I think you should be doing:
This, I would expect to create a table inside a text file. If it isn’t, then I have to look at what’s in $out to see why.
At the risk of being a commercial, I’d strongly suggest looking at “Learn Windows PowerShell in a Month of Lunches.” You’re running against some of the most common “gotchas” in how PowerShell works, and it’s exactly what the book walks you through. A lot of people have found it useful in getting started with the shell and understanding what’s actually happening.