Reputation: 940
My console output is too small - the IP addresses I'm getting output are truncated.
I know how to format output as a table, however, I am outputting data from a loop, and when i pipeline each output to a format-table
, I get a nice column width, but 3 blank lines+2 lines for the headline for every one line of actual data. This is quite annoying, and I could not find anything online on how to widen the columns WITHOUT using Format-Table.
What is a good way of either changing the size in general, OR using Format-Table
on the entire loop?
I do not want to append every output to a variable or a file, and then print it to the console - it needs to appear loop for loop in the console.
Here's what I mean, in case you wondering:
Before:
Name IPv4Address ---- ----------- PC12315274 192.168.10... PC17245658 192.168.10... NB12346679 192.168.12.38 PC12245614 192.168.10... SV12347348 192.168.10... PC62345678 192.168.10... SV12165667 192.168.17.28
When using Format-Table
in my loop:
Name IPv4Address ---- ----------- PC12315274 192.168.12.129 Name IPv4Address ---- ----------- PC62345678 192.168.14.161 Name IPv4Address ---- ----------- PC12165667 192.168.11.123 Name IPv4Address ---- ----------- NB12555662 192.168.17.125
Here is the relevant code:
foreach ( $subnet in (7..100)) {
foreach ( $client in (1..253)) {
get-adcomputer -filter "IPv4Address -eq '192.168.$subnet.$client'" -Properties * `
| select Name, IPv4Address
}
}
Upvotes: 0
Views: 862
Reputation: 5341
I've found that piping Select-Object
output to Format-Table
can cause similar issues. Try piping directly to ft without Selecting first
I also would recommend only querying AD once, then filtering addresses within powershell"
Get-ADComputer -filter * -Properties ipv4address |
where {
$_.ipv4address -ne $null -and
$_.ipv4address.split(".")[2] -in 7..100 -and
$_.ipv4address.split(".")[3] -in 1..253} |
ft name,ipv4address -autosize
Upvotes: 2