fix(Update-LithnetStore): import lists instead of crashing on the first one

The three import loops iterated `$set.ToArray() | Sort-Object` over
HashSet[string] collections. HashSet<T> has no ToArray instance
method - that is a LINQ extension method, which PowerShell does not
bind - so member-access enumeration applied .ToArray() to each string
in the set and threw "[System.String] does not contain a method named
'ToArray'". An empty set enumerates nothing and passes silently, but
the hash list is never empty (configured sources, or the default KHDB,
otherwise the script throws earlier). So every run opened the store,
crashed on the first import, and closed it again with nothing
imported. Same behavior on Windows PowerShell 5.1 and PowerShell 7.

Pipe the sets into Sort-Object directly, which enumerates them.

Found by the Pester test written for the upcoming module conversion.
Reproduced and verified end-to-end with a stub LithnetPasswordProtection
module on PSModulePath: before, Open-Store -> ToArray error ->
Close-Store; after, the KHDB, plaintext and banned-word lists are each
imported and the store is closed.
This commit is contained in:
2026-11-04 12:54:07 +01:00
parent 37a2baa5f0
commit 262b8ae0b8
2 changed files with 4 additions and 3 deletions
+1
View File
@@ -15,6 +15,7 @@ Starting with **v2.2.0**, Elysium uses a **unified project version**. All script
- `Update-LithnetStore.ps1` ignored `InstallationPath`/`WeakPasswordsDatabase` and always looked for `khdb.txt` next to the script; it now resolves the same KHDB path as the other scripts. It also writes a transcript to `Reports/logs/` like the other operational scripts and uses the shared settings parser instead of its own copy.
- The `Restart-WithPwshIfAvailable` / `Restart-WithWindowsPowerShellIfAvailable` relaunchers in `Elysium.Common.ps1` relaunched `Elysium.Common.ps1` itself instead of the calling script (`$PSCommandPath` inside a function is the file that defines it), then exited. Whenever a relaunch fired, the script silently did nothing: `Update-KHDB.ps1`, `Prepare-KHDBStorage.ps1`, `Update-LithnetStore.ps1` and `Uninstall.ps1` started from Windows PowerShell on a host with `pwsh` installed (including menu options 1, 4 and 5), and `Extract-NTHashes.ps1` / `Test-WeakADPasswords.ps1` started directly from `pwsh`. They now relaunch the calling script with its parameters.
- `Update-KHDB.ps1 -MaxParallelTransfers N`, as documented in the README, was silently ignored: the script had no `param()` block, so the value never reached the downloader and PowerShell 7 always used 5 concurrent transfers. The script now declares and forwards the parameter (values outside 1-64 are rejected).
- `Update-LithnetStore.ps1` failed on every run right after opening the store: it called `.ToArray()` on its `HashSet[string]` source lists, but `ToArray` is a LINQ extension method that PowerShell cannot see, so PowerShell applied it to each string in the set and threw. The hash list always has at least one entry (configured sources or the default KHDB), so no list was ever imported. The lists are now enumerated through the pipeline.
### Changed
- Elysium is becoming a PowerShell module (`src/Elysium`). The manifest's `ModuleVersion` is now the only place the version is defined; the per-file banner versions and `Bump-Version.ps1` are gone. Shared helpers moved from `Elysium.Common.ps1` into `src/Elysium/Private` (`Elysium.Common.ps1` is now a loader for them), and the KHDB updater is the first exported cmdlet, `Update-ElysiumKhdb`; `Update-KHDB.ps1` remains as a thin wrapper, so the menu and existing invocations are unchanged.
+3 -3
View File
@@ -143,17 +143,17 @@ try {
Sync-HashesFromHibp
}
foreach ($hashFile in ($hashSourcePaths.ToArray() | Sort-Object)) {
foreach ($hashFile in ($hashSourcePaths | Sort-Object)) {
Write-Host ("Importing NTLM hash list '{0}'..." -f $hashFile)
Import-CompromisedPasswordHashes -Filename $hashFile
}
foreach ($plainFile in ($plaintextSourcePaths.ToArray() | Sort-Object)) {
foreach ($plainFile in ($plaintextSourcePaths | Sort-Object)) {
Write-Host ("Importing plaintext password list '{0}'..." -f $plainFile)
Import-CompromisedPasswords -Filename $plainFile
}
foreach ($bannedFile in ($bannedWordSourcePaths.ToArray() | Sort-Object)) {
foreach ($bannedFile in ($bannedWordSourcePaths | Sort-Object)) {
Write-Host ("Importing banned word list '{0}'..." -f $bannedFile)
Import-BannedWords -Filename $bannedFile
}