5

I want to delete a specific value from hashtable.

The table looks like this:

Name                           Value                                                                                                                                             
----                           -----                                                                                                                                             
column                         {test, test2}    

How can I delete the "test2" value?

I tried the following:

$myhashtable.remove("test2")

which unfortunately does not work.

Could someone help me with this? Thanks!

1 Answer 1

7

The example that you provided looks like a hashtable of hashtables. So you would need to do:

$myhashtable['column'].Remove('test2')

If it is a hashtable where the value is an array, then you would need to do this:

$myHashTable['column'] = ($myHashTable['column'] | ?{$_ -ne 'test2'})
Sign up to request clarification or add additional context in comments.

7 Comments

It doesn't work, i have this error : Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size."
I did try it and it did work. This means that it is not a hashtable of hashtables. How do you populate $myHashTable?
With a little more testing it looks like it is probably a hashtable with an array for the value. If possible I think that your best bet would be to make sure that the value doesn't get into the array to begin with. Failing that you would need to make a new array minus the unwanted value then assing that in the hashtable.
So yeah, the addition to the answer should work. Complete information when asking questions will generally get you a more complete answer for future reference.
Errr, up there where I said assing, I meant assigning.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.