2026-05-31

PowerShell Local Resource Manager Part 10

krymtkts/pslrm の開発をした。

pslrm は Microsoft.PowerShell.PSResourceGet を module manifest の RequiredModules に指定していた。 ModuleVersion を指定して最低バージョンを宣言しているつもりだった。 しかし文書上は以下のように ModuleVersion を指定すると最低バージョンとなると書いてるけどそうならなかったようだ。

    # Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(
@{
ModuleName = 'Microsoft.PowerShell.PSResourceGet'
ModuleVersion = '1.0.0'
}
)

最低どころか exact 1.0.0 が同時に install 固定されてしまっていた。 仕方ないので最低バージョンの縛りを外したものを 0.0.1 で公開した。

    # Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(
# Keep PSResourceGet unpinned here.
# A pinned ModuleVersion turned into a fixed package dependency and blocked newer versions.
'Microsoft.PowerShell.PSResourceGet'
)

これで幾分マシになった。 しかしいまでも Windows PowerShell で pslrm を使おうとすると以下のようにややこしい設定をせねばならん。

    - name: Install modules from PSGallery (powershell)
shell: ${{ inputs.shell }}
if: inputs.shell == 'powershell'
run: |
# NOTE: -Repository PSGallery is required in Windows PowerShell CI to avoid untrusted repository prompts that cannot be bypassed in non-interactive mode.
if (-not (Get-Command Install-PSResource -ErrorAction SilentlyContinue)) {
Write-Host "Installing Microsoft.PowerShell.PSResourceGet to bootstrap pslrm installation."
Install-Module -Name Microsoft.PowerShell.PSResourceGet -Force -Scope CurrentUser -Repository PSGallery -SkipPublisherCheck -AllowPrerelease
# NOTE: PSResourceGet v1.2.0 may fail on first run unless the repository store is initialized.
# Cannot retrieve the dynamic parameters for the cmdlet. Loading repository store failed: Could not find a part of the path 'C:\Users\runneradmin\AppData\Local\PSResourceGet\PSResourceRepository.xml'.
Get-PSResourceRepository | Out-Null
}
Set-PSResourceRepository -Name PSGallery -Trusted
# NOTE: In Windows PowerShell CI, we bootstrap Microsoft.PowerShell.PSResourceGet before calling Install-PSResource.
# NOTE: pslrm declares PSResourceGet as a dependency, and the dependency install would otherwise try to replace the same loaded module under CurrentUser.
# NOTE: SkipDependencyCheck avoids that self-reinstall conflict.
Install-PSResource pslrm -Prerelease -Quiet -Scope CurrentUser -Repository PSGallery -SkipDependencyCheck
Restore-PSLResource

Windows PowerShell 環境には PSResourceGet が存在しないようなので念の為存在を確認した後に install 。 しかしここでも一癖あり、何故か $env:LOCALAPPDATA//PSResourceGet\PSResourceRepository.xml が不足する。 それを解消するためには先に Get-PSResourceRepository を打つ必要がある。 PowerShell Gallery は既定で信頼されないので信用したうえでようやく install できるようになる。 ちなみに -Repository PSGallery -SkipDependencyCheck がないと module が見つからなかったり install 時に失敗したりする。 Windows PowerShell での PSResourceGet の setup は難しすぎる。

奇しくも PSResourceGet が v1.3 から Windows PowerShell をサポート外にするという話もあるし、この煩雑な bootstrap は残り続けるのだろう。 pocofPSKeepAChangelogTools も Windows PowerShell をサポートしてるが面倒ではある。 PSResourceGet くらいでかいなら Windows PowerShell を切れたら相当楽になるだろう。 そして引きずられた pslrm ではどうすりゃいいんだ?となる。 現状 Windows PowerShell をサポートする限りは RequiredModulesPSEdition で分岐するしかないやろな。