Skip to content

Commit a8b353d

Browse files
committed
feat: 🆕 Add Measure-CommandInventory script
* Introduced `Measure-CommandCount` function to count unique commands. * Added `Measure-ModuleInventory` function to list available modules and their commands. * Enhanced command inventory tracking for better module management.
1 parent c1c3281 commit a8b353d

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function Measure-CommandCount {
2+
# Count the number of unique commands available.
3+
(Get-Command | Sort-Object -Property Source, Version | Group-Object -Property Name, Source -NoElement |
4+
Measure-Object).Count
5+
}
6+
7+
function Measure-ModuleInventory {
8+
<#
9+
List all available modules and the commands in each one.
10+
#>
11+
$Inventory = [ordered]@{}
12+
13+
$Commands = Get-Command | Sort-Object -Property Source, Name, Version |
14+
Select-Object Source, Name, Version | Group-Object -Property Source, Name -NoElement |
15+
Select-Object -ExpandProperty Name
16+
17+
$Commands | ForEach-Object {
18+
$Module, $Command = $_ -split ', '
19+
20+
if ([string]::IsNullOrEmpty($Module)) {
21+
$Module = '_UnnamedSourceModule_'
22+
}
23+
24+
if ($Inventory.Contains($Module)) {
25+
$Inventory[$Module] += $Command
26+
} else {
27+
$Inventory[$Module] = @($Command)
28+
}
29+
}
30+
31+
$Inventory
32+
}
33+
34+
$Inventory = Measure-ModuleInventory
35+
$Inventory.Count
36+
37+
$CommandCount = 0
38+
foreach ($item in $Inventory.GetEnumerator()) {
39+
$CommandCount += $item.Value.Count
40+
}
41+
$CommandCount

0 commit comments

Comments
 (0)