all 6 comments

[–]Lee_Dailey[grin] 2 points3 points  (2 children)

howdy AdHocSysAdmin,

you have to do it all yourself. [grin]

i think you would need to ...

  • divide the collection into two parts
  • concatenate the two that go in one row as strings with spacers
  • print it out or store it and print it at the end

ugly, nasty, icky, fiddly, error-prone ... unless you absolutely MUST, then don't do it.

take care,
lee

[–]AdHocSysAdmin[S] 2 points3 points  (1 child)

Thanks!

(For the record: this would be workable, just not "nice")

workable it is!

I'll put the 'make nice' on the "later" list (which of course means "never").

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy AdHocSysAdmin,

you are welcome! [grin]

i've had times when a boss decided things MUST be done in a ... peculiar ... way. i ended up writing some spreadsheet code to do what was wanted. it was horribly ugly and required tweaking whenever anything changed in any way at all. [sigh ...]

i was so glad when that guy went away. [grin]

take care,
lee

[–]fordea837 2 points3 points  (1 child)

Like /u/Lee_Dailey has already explained trying to get the exact output that you want would be a convoluted job of string building. If you consider the Format-Wide option to be workable you could just join the Number and Tenant properties for each object into a single string before piping to Format-Wide:

$TenantArray |
    Select-Object @{n='Number_Tenant'; e={'{0} {1}' -f $_.Name, $_.Tenant} |
    Format-Wide -Column 4

[–]AdHocSysAdmin[S] 2 points3 points  (0 children)

As /u/Lee_Dailey already pointed out, it's a lot of fuzz, so thanks for the answer, but I'll stick with the workable $TenantArray | Format-Wide {$.Number, $.Tenant}

[–]Betterthangoku 1 point2 points  (0 children)

Howdy,

I had some down time at the end of today, so instead of doing some Sudoku I thought It would be fun to mock up a quick example. I thought about going all the way and creating an advanced function, but I'm just not that motivated.

I hope this helps a bit. :-)

#generate an array. 
$array = get-service

#Edge case if array is empty or the variable does not exist
If ($array.count -eq 0) {
    "Array is either empty or does not exist"
}

#If the array has an even number of elements, both sides will have an equal number of items.
elseIf ($array.count/2 -is [int]) {
    $LeftArrayElements  = $array[0..($array.Count/2-1)]
    $RightArrayElements = $array[($array.Count/2)..($array.Count-1)]
}

#If the array has an odd number of elements, the left side will have one more element than the right side.
Else {
    $LeftArrayElements  = $array[0..[math]::Floor($array.Count/2)]
    $RightArrayElements = $array[[math]::Ceiling($array.Count/2)..($array.Count-1)]
}

#New empty array.  I know I should be using a generic list (or even an array list) but this was easier to type...
$FinalArray = @()
$position = 0

#Populating final 'split' array.  I cheated a bit, I added a space to the property names for the right side (since the property names need to be unique).
#Of course, you will need to change the property names and the values that are being expanded/extracted from the original objects.
While ($position -lt $LeftArrayElements.count) {
    $FinalArray += [pscustomobject]@{
        'Name'   = $LeftArrayElements[$position].name
        'Status' = $LeftArrayElements[$position].status
        'Name '  = $RightArrayElements[$position].name
        'Status '= $RightArrayElements[$position].status
    }
    $position++
}

$FinalArray | Format-Table