On testing, PowerShell is implicitly casting to the datatype of your variable to [double]. Instead, explicitly cast as [decimal]
- Double datatype can hold a wide range of values, but sacrifices exact precision.
- Decimal uses more memory (12 bytes as oppose to 8 in double) and has a shorter range of values but retains precision.
This is by no means an in-depth comparison; I recommend you read this table of datatypes and look online for a more complete explanation as this is very fundamental and is language-agnostic.
Code
foreach($entry in $arr){
...
switch($entry.AccessRights)
{
"GenericRead" {[decimal]$score = 1}
"GenericWrite" {[decimal]$score = 2}
"GenericAll" {[decimal]$score = 3}
default {[decimal]$score = 0.1}
}
$users | where {$_.username -eq $entry.username} | % {$_.aclscore+=$score}
}
Edit - Further explanation
Lack of precision in the double data type arises because numbers are stored in binary, and some numbers cannot be expressed exactly in binary.
Walter Mitty's comment provides a good example of a 1/3, a number that cannot be expressed exactly using a finite number of digits in decimal, or in binary:
1/3 = 0.333333333..... [decimal]
1/3 = 0.010101010..... [binary]
Similarly, the fraction 1/10 cannot be expressed exactly in binary. Whereas it can in decimal.
1/10 = 0.1 [decimal]
1/10 = 0.000110011.... [binary]