How it works...
The first two lines in the script have already been seen: they initialize a hashtable and add the processes to the hashtable. The rest of the script simply uses the members of the hashtable to give us the necessary information. For instance, Count is a property within the object. The Contains() method looks for the key, pwsh, and reports True or False based on whether it finds the key. The Remove() method removes the element identified by the key.
If you simply call $Processes, the list will be unsorted. In order to sort the keys or values, we use the GetEnumerator() method, so that PowerShell treats the hashtable as an object with two properties (Name and Value). Only then will you be able to sort the hashtable by name or ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access