In a PowerShell script I needed to sort a hash table by byte value (not alphabetically, lowercase parameters will be listed after uppercase ones). An example for this requirement is the Amazon Product Advertising API.

Consider the following hashtable as an example:

If we use the Sort-Object to order the list (note that we need to use the GetEnumerator method):

We will get the following result:

If you use the -CaseSensitive switch the resulting order will remain the same.

I came up with the following code (download link below) to sort the hashtable in the required order:

Let’s try that:

Download PowerShell Script