SUT
SUT

Reputation: 323

Dictionary with multiple values per key

I need a datatype for the PowerShell to add different values to a key. which type should I choose?

The data are like:

+--------+--------+--------+--------+   
| Serv1  | Serv2  | Serv3  | Serv4  |   
| -------+--------+--------+------- |    
| User1  | User2  | User3  | User4  |   
| User3  | User1  | User2  | User4  |   
| User7  | User8  | User9  | ------ |   
+--------+--------+--------+--------+

Upvotes: 0

Views: 6994

Answers (1)

briantist
briantist

Reputation: 47832

This would be easier to answer with more information. But based on that, it looks like a [hashtable] where the values are arrays is what you want.

Example:

$hash = @{
    Serv1 = @(
        'User1',
        'User3',
        'User7'
    )

    Serv2 = @(
        'User2',
        'User1'
    )
}

# add a new user to an existing key

$hash.Serv2 += 'User8'

# add a new key

$hash.Serv3 = @(
    'User3',
    'User2'
)

Upvotes: 5

Related Questions