How to clear all values from the Hash table in PowerShell?

Hash table in the PowerShell session is created temporarily. It is like a variable, when the session is closed, hash table is deleted automatically. If you want to delete all the values from the hash table at once but retaining the hash table variable, you need to use the Clear() method.

We have the hash table below created already.

$htable = [Ordered]@{EmpName="Charlie";City="New York";EmpID="001"}

PS C:\WINDOWS\system32> $htable
Name       Value
----       -----
EmpName    Charlie
City       New York
EmpID      001

To clear the above hashtable,


If you check the hash table data, it won’t display anything now but it is still the OrderedDictionary and not converted into any variable data type.