- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add and remove values to the Hash Table in PowerShell?
You can add values to the hash table and remove values from the hash tables. To add the values to the hash table, you need to use the below format.
$hash["<key>"] = "<value>"
We have hash table already created here,
$htable = [Ordered]@{EmpName="Charlie";City="New York";EmpID="001"}
PS C:\WINDOWS\system32> $htable Name Value ---- ----- EmpName Charlie City New York EmpID 001
We need to add additional key “Dept” in the above hash table with the value “Technical”.
$htable['Dept']="Technical"
When you check the output of the above Hashtable, you can see the key-value is appended to the table.
PS C:\WINDOWS\system32> $htable Name Value ---- ----- EmpName Charlie City New York EmpID 001 Dept Technical
You can also use the Hashtable method called Add() to add the value. The format is as below.
Add(Key, Value)
To add the same above mentioned Key-Value to the hashtable with the Add() method,
$htable.Add('Dept','Technical')
To remove the Key-value from the Hashtable, you need to use the Remove(Key) method.
For example, to remove the Key “Dept” from the hashtable,
$htable.Remove('Dept')
PS C:\WINDOWS\system32> $htable Name Value ---- ----- EmpName Charlie City New York EmpID 001
You cannot remove the hashtable entry with the values. You must use the key inside the Remove() method.
- Related Articles
- How to clear all values from the Hash table in PowerShell?
- How to add/remove values in the array in PowerShell?
- How to create a Hash Table in PowerShell?
- How to add/merge two hash tables in PowerShell?
- What is Hash Table in PowerShell?
- How to add multiple values in the Hashtable using PowerShell?
- Add elements to a hash table using Javascript
- Remove elements from Javascript Hash Table
- How to add help in the PowerShell function?
- How to add a specific character to any empty space in MySQL table values?
- How to overwrite or remove PowerShell alias?
- How to remove windows features using PowerShell?
- How to remove Windows service with PowerShell?
- How to add and remove error bars in Excel?
- How to Add and Remove multiple classes in jQuery?
