-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_functions.ps1
40 lines (31 loc) · 1.07 KB
/
random_functions.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function ConvertTo-SortedDictionary {
<#
.SYNOPSIS
Converts a hashtable into a sorted dictionary.
.DESCRIPTION
The ConvertTo-SortedDictionary function takes a hashtable as input and converts it into a sorted dictionary. The resulting sorted dictionary will have its keys sorted in ascending order.
.PARAMETER HashTable
The hashtable to be converted into a sorted dictionary.
.EXAMPLE
$hashTable = @{
"Key3" = "Value3"
"Key1" = "Value1"
"Key2" = "Value2"
}
$sortedDictionary = ConvertTo-SortedDictionary -HashTable $hashTable
This example demonstrates how to convert a hashtable into a sorted dictionary using the ConvertTo-SortedDictionary function.
.INPUTS
System.Collections.Hashtable
.OUTPUTS
System.Collections.Generic.SortedDictionary[string, string]
#>
param(
[Parameter(Mandatory = $true)]
[System.Collections.Hashtable]$HashTable
)
$SortedDictionary = New-Object 'System.Collections.Generic.SortedDictionary[string, string]'
foreach ($Key in $HashTable.Keys) {
$SortedDictionary[$Key] = $HashTable[$Key]
}
Write-Output $SortedDictionary
}