Iam trying to use Format-Table to print some process data. I started with testing the output directly in the shell. Something along the lines of (Get-Process is just a substitute for my data):
Get-Process | Format-Table ProcessName, Id
The problem is that the first column has some larger cells and i needed to set up some formatting like this:
$tableFormat = @{Expression={$_.ProcessName}; width=70}, @{Expression={$_.Handles}};
Get-Process | Format-Table $tableFormat
In both cases, the output looked fine inside the shell. This is an example with $tableFormat:
DeviceDisplayObjectProvider 240
dllhost 198
dwm 78
explorer 1077
explorer 599
fpassist 61
Idle 0
inetinfo 409
InetMgr 314
lsass 1132
lsm 167
mqsvc 235
msdtc 152
MsDtsSrvr 165
notepad++ 249
Opc.Ua.ComServerWrapper 526
Opc.Ua.DiscoveryServer 530
OpcEnum 85
OPCSim 204
pageant 111
powershell 489
powershell_ise 442
PresentationFontCache 151
procexp 183
PROCEXP64 373
ReportingServicesService 693
services 302
smss 30
SMSvcHost 298
SMSvcHost 151
When i attempt to print the table to the default printer like this
...
Get-Process | Format-Table $tableFormat | lp
The result has broken columns (taken from a pdf printer, real output looks the same):
Other things I've tried so far:
- Set the column alignment for all columns explicitly to left
- autoSize(makes things worse)
This problem might be related to my previous question, when i still tried to manually format the table with tabs. See: Why does Powershell Out-Printer ignore `f (new page) in text?