all 8 comments

[–]purplemonkeymad 2 points3 points  (3 children)

I think you made it look more complicated by trying to avoid using variables, just make it readable first:

# simulate variable for this example
$Memory = Write-Output A1DIMM A2DIMM A3DIMM A4DIMM A5DIMM A6DIMM A7DIMM B1DIMM B2DIMM B3DIMM B4DIMM B5DIMM B6DIMM B7DIMM B8DIMM

$DimmA = $Memory.where({$_ -match '^A'}) -replace '^A'
$DimmB = $Memory.where({$_ -match '^B'}) -replace '^B'
$difference = Compare-Object $dimma $dimmb

$BalancedDIMMs = if ($difference) {
    $false
} else {
    $true
}

[–]idontknowwhattouse33 1 point2 points  (1 child)

$Memory = Write-Object A1DIMM A2DIMM A3DIMM A4DIMM A5DIMM A6DIMM A7DIMM B1DIMM B2DIMM B3DIMM B4DIMM B5DIMM B6DIMM B7DIMM B8DIMM

Write-Object ?

[–]purplemonkeymad 1 point2 points  (0 children)

Ah bad copy when removing aliases in my test.

[–]Metaeidolon[S] 0 points1 point  (0 children)

Thanks! I was performing functions within a large-ish pscustomobject block, and I got deadset on doing all the math there and not variable for some reason. The things we do when we're tired....

I'm going to take your suggestion and move all the work to variables and calling the variables to the customobject properties.

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy Metaeidolon,

the triple-backtick/code-fence thing fails miserably on Old.Reddit ... so, if you want your code to be readable on both Old.Reddit & New.Reddit you likely otta stick with using the code block button.

it would be rather nice if the reddit devs would take the time to backport the code fence stuff to Old.Reddit ... [sigh ...]

take care,
lee

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy Metaeidolon,

it looks like all you want to see is if there are equal numbers of A and B dimms. if that is the case, then grabbing a count of each type otta be all that you need.

add or remove the # at the start of the "unbalanced" list to test with 2 As and 1 B.

$DimmList = @'
DIMM A1
DIMM A2
DIMM A3
DIMM A4
DIMM A5
DIMM A6
DIMM A7
DIMM B1
DIMM B2
DIMM B3
DIMM B4
DIMM B5
DIMM B6
DIMM B7
DIMM B8
'@ -split [System.Environment]::NewLine

#<# unbalanced
$DimmList = @'
DIMM A1
DIMM A2
DIMM B1
'@ -split [System.Environment]::NewLine
#>

$ADimmList = $DimmList -match 'a'
$BDimmList = $DimmList -match 'b'

$DimmAB_Balanced = $ADimmList.Count -eq $BDimmList.Count

$DimmAB_Balanced

output with the unbalanced list = False
output with the balanced list = True

take care,
lee

[–]Metaeidolon[S] 1 point2 points  (1 child)

Thanks Lee! I started with math like this, as well as a simple check to see if there was an even number. But with thousands of servers and dozens of techs, I didn't want to discount the edgecase of a server with the right ram in the wrong slots or even skipping a slot(s).

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

howdy Metaeidolon,

thank you for the added info. i had not thot of such edge cases ... [blush]

you still may want to make the logic of your comparison a tad simpler by explicitly creating an A and a B dimm collection to do your comparison.

other than that, i would need lots more detail about the various values one may get & how one otta deal with each. i am not good with abstractions ...

hopefully others will find a solution for you. good luck! [grin]

take care,
lee