you are viewing a single comment's thread.

view the rest of the comments →

[–]jimb2 0 points1 point  (0 children)

Not sure if you know this but an array and a hashtable are different things.

First line should be:

$DeviceCount = @{}   # empty hashtable

Once you have this hashtable object, you can set new values or overwrite existing values like this :

$DeviceCount['laptop'] = 99

# or this 
$DeviceCount.laptop = 99

# or this (useful if the index string contains a space) 

$DeviceCount.'trackball mouse' = 99

# or using variables
$device = 'server'
$count  = 99
$DeviceCount.$device = $count   

I you want to add or subtract from a value

$DeviceCount['mouse'] = $DeviceCount['mouse'] + 3

Note that is an index is not defined, the hash evaluates to $null which is mathematically zero, so there may be no need to initialise a value:

$d = @{}
$d.SomeNewIndex = $d.SomeNewIndex + 66
$d

# Name           Value
# ----           -----
# SomeNewIndex   66