powershell - Check if a number belongs to a list -
i want ot verify if user entered number belongs predefined list, -contains
operator behaves different expected:
0 -contains 0. true
the list generated command (get-disk).number
. have false
input 0.
?
first, should wrap output of (get-disk).number
@()
force list array. then, ensure array of strings using cast. finally, pass number want check using string:
[string[]]$list = @((get-disk).number) # list contains 0 $list -contains "0." # false
the double 0.
eqal int 0
equal string "0"
have pass string.
Comments
Post a Comment